Adds a segment builder for merging multiple segments #552
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
When merging a large number of segments together we were doing a tremendous amount of allocation especially related to strings due to concatenation.
This adds an internal
SegmentBuilder
that uses aStringBuilder
for building up the text rather than creating a new instance and doing a concat operation for each segment.Here's the perf for a 10,000-node tree.
Before
After
In the before you'll notice we are doing 44gb of memory allocations, mostly strings. Afterwards thanks to the
StringBuilder
this drops to 44mb. Performance obviously comes with this too, as the time to build goes from 32s down to 133ms. Not too shabby!Unit tests all pass, obviously, but @patriksvensson I definitely could use a careful eye and feedback here because I get nervous anytime I write code that messes with the control characters :-)
Fixes #551