2 ms·
25% is great! You're right, there might be more here, and it's always a good idea to be charitable in your reading, that's absolutely worth keeping in mind. It
by dahart 8y ago
25% is great! You're right, there might be more here, and it's always a good idea to be charitable in your reading, that's absolutely worth keeping in mind.
It's just that the headline sales pitch of the post is "from 7GB to 32KB". Unfortunately, that doesn't mean much and it's misleading. As is the title "Strings are evil". Those sentences combined with no obvious reason to ignore the primary optimization metrics and instead focus on something that doesn't affect either memory usage or run time very much, those things together make me feel like it's more likely the author either wanted a good blog post, or doesn't have a ton of experience with optimization. Those are both great, but that's no reason for me not to comment and try to add some clarity.
To me it seems a bit strange to say that time taken was not the main focus, and follow that with "reduce the time spent in GC." The singular primary reason to reduce allocations is to reduce run time of the program, there is no other reason here.
FWIW, it's highly likely that this program's run time could be further improved by more than 2x by allocating a single buffer the size of the file and doing a single fread() call, then processing the entire file in memory. That would increase the working set from 16MB to 300MB, or whatever the file size is, but would allow much faster processing than line buffered input.