Closed Numpsy closed 1 year ago
@Numpsy thanks a lot for trying out this kind of stuff.
In this case, I don't see the benefits of improving this part. We're just boosting only a few us in perf and only a few KB in allocations, so I think it's not worth it if we put the code readability in the equation.
Anyway, I want to say thanks for taking a look into it and for your help.
I don't see the benefits of improving this part.
Yeah, one of those things where you can't really tell how much effect it'll have without making the change and measuring it, and the tiny perf change might just be a side effect of less GC allocations. I'll shelve this one for now.
As suggested elsewhere, an attempt at using CopyString with a reused buffer rather than using GetString (which creates a new temporary string each time) - the idea being that the strings are added to a StringBuilder and then discarded anyway.
It's just a draft, as I don't know what the array management strategy should be (I gave it a quick try at using ArrayPool just inside AddElement and got slightly lower memory usage but also slightly slower performance, so there is probably room to tweak things more).
Anyway - with the current code I get this when testing the dark theme, C# grammer and TS grammer (I added the TS grammer as a test because there are strings in it over 7000 chars long, so reading it needs larger buffers).
And with this change, I get