-
Notifications
You must be signed in to change notification settings - Fork 1.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
StringInputStream gets stuck at large enough stdin input #555
Comments
This comment was originally written by [email protected] Added Area-Library, Triaged labels. |
This is due to extremely high new space usage by StringInputStream. Using the |
The problem is the StringBuffer _result field of _StringDecoderBase in string_stream.dart. Characters get added individually to this buffer as long Once toString has been called on the buffer, then the buffer can be freed, and we are using much less memory per character. We need some way to do this after about every 10000 - 100000 characters. I think we need a 2-level scheme of StringBuffers, so that every 100,000 characters get written to a string, and those strings are accumulated in a higher level StringBuffer. Other than that, we would need a way in which all uses of a decoder would keep calling the decoder until they got all the data in large chunks. |
A simpler solution would be to use List<int> charcodes to accumulate the string, instead of a StringBuffer, since Lists can be efficiently extended, and create the string from it when it is read from the decoder. There is no good reason to use a StringBuffer, since we are adding a character at a time, by knowing its character code. Or maybe StringBuffer itself should know to concatenate itself to a single string, and |
Added a CL that fixes this, http://codereview.chromium.org/8639004/, by accumulating the character codes in a List<int>, not a StringBuffer. StringBuffers are mainly useful for accumulating many strings, of varying lengths. List<int> is better for single characters. |
Fixed by commit r1777, but note bug 571 : http://code.google.com/p/dart/issues/detail?id=571 Added Fixed label. |
Revisions updated by `dart tools/rev_sdk_deps.dart`. collection (https://github.com/dart-lang/collection/compare/e8d7e92..f309148): f309148 2023-11-08 Kevin Moore Latest lints, require Dart 3.1, use mixin (#322) fixnum (https://github.com/dart-lang/fixnum/compare/3279f5d..6b0888c): 6b0888c 2023-11-08 Kevin Moore Update to latest lints and fix (#122) markdown (https://github.com/dart-lang/markdown/compare/efb73b3..3774ad0): 3774ad0 2023-11-07 Kevin Moore Fix formatting for latest Dart dev SDK (#565) da11847 2023-11-07 Mosc Fix beginning of line detection in `AutolinkExtensionSyntax` (#555) tools (https://github.com/dart-lang/tools/compare/d898ad1..dd46ef2): dd46ef2 2023-11-09 Elias Yishak Enum + event constructor added for `flutterCommandResult` (#199) Change-Id: I8aa33f52c8afd50b60b225ad890f3e82945bcc50 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/335303 Reviewed-by: Konstantin Shcheglov <[email protected]> Auto-Submit: Devon Carew <[email protected]> Commit-Queue: Konstantin Shcheglov <[email protected]>
This issue was originally filed by [email protected]
What steps will reproduce the problem?
main() {
var a;
var ios = new StringInputStream(stdin);
while ((a = ios.read()) !== null) {
print(a.length);
}
exit(0);
}
dart_release wrangler.dart < mega_sample.txt
What is the expected output? What do you see instead?
It should print the length of the input string. But it gets stuck like in an endless loop and doesn't print anything and doesn't exit either.
What version of the product are you using? On what operating system?
Bleeding-edge Dart. Linux manga 3.0.0-13-generic-pae #22-Ubuntu SMP Wed Nov 2 15:17:35 UTC 2011 i686 i686 i386 GNU/Linux
Please provide any additional information below.
I'm attaching the sample file. Here's the output when the program works for a slightly smaller input file:
$ time dart_release wrangler.dart < mega_sample.txt
837083
real 0m4.274s
user 0m4.236s
sys 0m0.036s
And when it gets stuck and has to be canceled:
$ wc mega_sample.txt
4960 10416 840472 mega_sample.txt
$ time dart_release wrangler.dart < mega_sample.txt
^C
real 0m52.132s
user 0m52.083s
sys 0m0.032s
Attachment:
mega_sample.txt (820.77 KB)
The text was updated successfully, but these errors were encountered: