Admittedly, I liked the write up. It's a fun exercise to go over, but I would ask my devs to go with the original program.
Premature optimization is the root of all evil. - Knuth
“We should forget about small efficiencies, say about 97% of the time: premature optimization is the root of all evil. Yet we should not pass up our opportunities in that critical 3%.”
AFAIK .NET has a concurrent garbage collector. For all we know there was a 2nd core running 100% to collect strings that is now almost entirely idle. It's possible the effort more than doubled overall throughput if you consider the ability to run multiple jobs.
That said, ad hoc parsing is a fundamentally messy approach in every language, not just languages like C with poor string handling.[1] Parser generators exist for a good reason--easier to read and great performance without even trying. Find a good one for your language of choice. The learning curve is steep but you'll never look back.
[1] Actually, I find C one of the best languages for parsing as you're much less likely to conflate string manipulation with parsing. Though that realization comes more quickly for some than for others.
If the GC is the problem, you can pool the message instances.
About the only place where you parse strings is if you're dealing with human input or something almost unstructured like aforementioned CSV.
But the author presumably has some reason for focusing on allocations (and GC generations, though that never really comes up). Perhaps the subject code is causing excessive GC pauses in the larger program it is part of? If they're doing "real-time calculations" as part of financial services, I can see where adding latency for several seconds could be a bad thing.
"Currently this import process has to take place outside of business hours because of the impact it has on memory usage."
That statement is pretty confusing to me; if the high watermark is 16MB, there's no memory usage problem to begin with. And if saving 25% CPU time is enough to go from after hours to during business hours, it won't take much to push the jobs back to after hours, right?
The hyperbole in the title & headlines combined with the vague issue of memory usage also leads me to believe this might be more about exposure for the blog post than fixing a problem. That's perfectly fine, but it's also okay to discuss and question what we're presented with, right?
It all feels to me like optimizing to the wrong metric. If you really want a parser to go fast, then eliminate line buffered input and block read the thing. Then eliminate all other memory allocations and process the file in memory. That will increase the memory usage in this case substantially, but it will be much faster than the improved version v11 they ended up with.
Great - 25% is nothing to sneeze at. Just noting that memory wasn't the problem.
And of course there's a hidden development cost to doing fancy indexing on strings rather than being comfortable with String.Split() making your parser go 25% slower. The code at the start is more functional, it's easier to look at and know it will do what's expected. The optimized code took longer to write, and it's harder to understand, and harder to modify.