[object writer] Use binary search for seeking SectionData positions - #132089
Draft
adamperlin wants to merge 1 commit into
Draft
[object writer] Use binary search for seeking SectionData positions#132089adamperlin wants to merge 1 commit into
adamperlin wants to merge 1 commit into
Conversation
Store buffer offsets separately and use them to locate stream positions in logarithmic time. Add targeted ObjectWriter coverage for mixed and empty buffers. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> Copilot-Session: b522a420-c4c0-4c17-a82f-45a026f6a64e
|
Azure Pipelines: Successfully started running 3 pipeline(s). 13 pipeline(s) were filtered out due to trigger conditions. There may be pipelines that require an authorized user to comment /azp run to run. |
Contributor
|
Tagging subscribers to this area: @agocke, @dotnet/ilc-contrib |
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes random seeking within SectionData’s read stream by maintaining a parallel list of per-buffer starting offsets and using a binary search to map a requested stream position to the correct underlying buffer in O(log N) time (instead of walking buffers linearly). This targets a potential perf trap in workloads that perform frequent random seeks during object writing.
Changes:
- Track per-buffer starting offsets in
SectionDataand use an “upper bound” binary search to resolve stream positions efficiently. - Add a regression test that exercises seeking across many small/empty buffers plus appended data.
- Expose internals to the test assembly via
InternalsVisibleTo.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| src/coreclr/tools/Common/Compiler/ObjectWriter/SectionData.cs | Add _bufferOffsets and switch ReadStream.Position seek logic to binary search over offsets. |
| src/coreclr/tools/aot/ILCompiler.Compiler/ILCompiler.Compiler.csproj | Add InternalsVisibleTo to allow test access to internal types like SectionData. |
| src/coreclr/tools/aot/ILCompiler.Compiler.Tests/ObjectWriterTests.cs | New test validating correct Position/ReadByte behavior across many buffers and appended data. |
| src/coreclr/tools/aot/ILCompiler.Compiler.Tests/ILCompiler.Compiler.Tests.csproj | Include the new ObjectWriterTests.cs in the test project build. |
This was referenced Aug 10, 2026
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.
Store buffer offsets separately and use them to locate stream positions in logarithmic time in
ObjectWriter\SectionData.cs. Note that from my testing this does add about 2.25 MB overhead working memory to a System.Private.CoreLib R2R compilation (out of 700+ total MB) but hugely reduces a perf trap that could be hit by random seeks over SectionData. This came up as part of my work on #132029; I definitely understand if we don't want the added overhead, but this wasn't too difficult to improve so I thought I'd put up a fix just in case.