News for hackers. Stuff that matters.
Re:Strings Are Evil by dahart on Wednesday June 20, 2018 @02:10PM (#17358000)
Make sure to look over the table at the end. They saved 2 seconds of run time. They didn’t reduce much memory, they reduced heap allocations. It’s the same as allocating and then releasing a 1MB array 1000 times and then worrying that you’ve used a gigabyte, even though the most you ever had allocated was 1MB.
Re:Strings Are Evil by ocdtrekkie on Wednesday June 20, 2018 @02:19PM (#17358086)
I would argue reducing the time spent and memory used both by 25% is pretty significant, considering this is one of presumably a large number of jobs.

The comments on the article also state: "With regards to time taken and peak working set, that was not our main focus. Our main focus was to reduce the number of allocations and reduce the time spent in GC. Unfortunately this data import process is not a standalone one time application. It is a part of a much larger application which is core to our entire platform."

It's possible that this has no meaningful impact to their application, but it's far more likely that the blog author just hasn't provided you all of the information you need to understand why it's important. I feel reading charitably is the best case here.

Re:Strings Are Evil by dahart on Wednesday June 20, 2018 @03:27PM (#17358842)
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.