Re:Strings Are Evil
by WorldMaker on Wednesday June 20, 2018 @01:08PM
(#17357257)
The article's comments point out heavily that they missed lazier generators/iterables (LINQ) as the obvious place to start and a key to both readability and minimizing memory footprint. Even if they preferred yield return style generators to LINQ from/where/select, and even if the code was otherwise the same within the scope generators, fewer of the allocations would leave the GC "nursery", and thus overall less memory needs (if more likelihood of GC Gen 0 collections thrashing some of their CPU, but this isn't a CPU-bound process so that's not a huge concern).
Sometimes the simpler, easier to read solution is the right one.
That said, the complex, advanced new solution to try that is also missing in their efforts in this article is Span<T>, and its ability to immutably splice strings in stack space (no GC allocations at all). (This is what parsers in the ASP.NET HTTP stack have been moving to.)
Sometimes the simpler, easier to read solution is the right one.
That said, the complex, advanced new solution to try that is also missing in their efforts in this article is Span<T>, and its ability to immutably splice strings in stack space (no GC allocations at all). (This is what parsers in the ASP.NET HTTP stack have been moving to.)