Avoid duplicate cache traversal for relative lists - #30
Merged
Conversation
Contributor
There was a problem hiding this comment.
Pull request overview
This PR optimizes dyld shared cache relative list-list parsing by introducing a single helper that resolves the target Mach-O image, its backing cache, and the correct cache-relative file offset together, reducing repeated cache/subcache traversal at each call site.
Changes:
- Add
MachOFile.relativeListLocation(for:)to resolve(image, backing cache, file offset)in one step. - Update method/property/protocol relative list-list readers to use the resolved backing cache’s file handle for header reads.
- Remove duplicated
cacheAndFileOffset(fromStart:)+_machO(at:)lookups at the call sites.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| Sources/MachOObjCSection/Model/Protocol/ObjCProtocolRelativeListList.swift | Switch protocol relative list-list header reads to use relativeListLocation(for:) and return the resolved image. |
| Sources/MachOObjCSection/Model/Property/ObjCPropertyRelativeListList.swift | Use relativeListLocation(for:) for backing-cache header reads and is64Bit from the resolved image. |
| Sources/MachOObjCSection/Model/Method/ObjCMethodRelativeListList.swift | Use relativeListLocation(for:) for backing-cache header reads and is64Bit from the resolved image. |
| Sources/MachOObjCSection/Extension/MachOFile+.swift | Introduce relativeListLocation(for:) helper to resolve image/cache/fileOffset together for relative list-list entries. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
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
relativeListLocation(for:)to resolve the Mach-O image, backing dyld cache, and file offset togethercacheAndFileOffsetand_machO(at:)lookupsWhy
Relative list-list entries need three related values: the image selected by
imageIndex, the cache file that backs that image, and the list's file offset. Resolving these independently caused overlapping cache/subcache scans at each method, property, and protocol list call site.The new helper keeps those values associated and performs the lookup once. The returned file offset is intentionally read through the located cache's file handle; it is not assumed to match the image's own file handle.
Benchmark
Compared clean worktrees of
mainand this commit with:Median results:
Instruction count was effectively unchanged (1169M to 1167M).
Validation
git diff --check main...HEADmainbaseline