perf: improve StringArray builder append paths#331
Merged
CurtHagenlocher merged 4 commits intoapache:mainfrom Apr 26, 2026
Merged
perf: improve StringArray builder append paths#331CurtHagenlocher merged 4 commits intoapache:mainfrom
CurtHagenlocher merged 4 commits intoapache:mainfrom
Conversation
BenchmarkDotNet ShortRun, StringBuilderAppendBenchmark, 10,000 ASCII strings of length 32: - AppendSmallStrings: 432.0 us / 1.66 MB -> 341.0 us / 1157.5 KB - AppendRangeSmallStrings: 426.2 us / 1.66 MB -> 311.8 us / 353.68 KB
Write encoded string bytes directly into the builder value buffer after reserving capacity, avoiding both stackalloc staging and an extra copy while keeping offsets and validity updates unchanged. BenchmarkDotNet (StringBuilderAppendBenchmark): AppendSmallStrings 393.1 us / 1157.5 KB; AppendRangeSmallStrings 290.5 us / 353.68 KB.
Encapsulate the reserve/get-span/advance sequence in BinaryArray.BuilderBase so StringArray.Builder can encode directly into the value buffer without owning the low-level buffer length bookkeeping. BenchmarkDotNet (StringBuilderAppendBenchmark): AppendSmallStrings 383.7 us / 1157.5 KB; AppendRangeSmallStrings 294.4 us / 353.68 KB.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
StringArray.Builder.Append(string)values by encoding into stack memory before appending.AppendRangeinputs.AppendRange(ICollection<string>)now performs a counting prepass to reserve value-buffer capacity before appending, so collection inputs are enumerated twice by design.Benchmark
BenchmarkDotNet ShortRun,
StringBuilderAppendBenchmark, 10,000 ASCII strings of length 32:AppendSmallStringsAppendRangeSmallStringsValidation
dotnet test test/Apache.Arrow.Tests/Apache.Arrow.Tests.csproj -c Release --filter "FullyQualifiedName~Apache.Arrow.Tests.StringArrayTests"rtk dotnet build "Apache.Arrow.sln" -c Release