Skip to content

Avoid duplicate cache traversal for relative lists - #30

Merged
p-x9 merged 1 commit into
mainfrom
codex/relative-list-location
Jul 17, 2026
Merged

Avoid duplicate cache traversal for relative lists#30
p-x9 merged 1 commit into
mainfrom
codex/relative-list-location

Conversation

@p-x9

@p-x9 p-x9 commented Jul 17, 2026

Copy link
Copy Markdown
Owner

Summary

  • add relativeListLocation(for:) to resolve the Mach-O image, backing dyld cache, and file offset together
  • use the resolved backing cache when reading relative method, property, and protocol list headers
  • avoid repeating cache/subcache traversal through separate cacheAndFileOffset and _machO(at:) lookups

Why

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 main and this commit with:

DyldCache.MachOFile.objc.classInfo.withMethodRelativeList.first100

Median results:

Metric main This PR Change
Wall time 65.2 ms 59.9 ms 8% faster
CPU time 64.6 ms 59.9 ms 7% faster
Throughput 15/s 17/s 13% higher
Peak RSS 40 MB 39 MB 2% lower

Instruction count was effectively unchanged (1169M to 1167M).

Validation

  • git diff --check main...HEAD
  • focused benchmark comparison against a freshly generated main baseline

@p-x9
p-x9 requested a review from Copilot July 17, 2026 15:53
@p-x9
p-x9 marked this pull request as ready for review July 17, 2026 15:53

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

@p-x9
p-x9 merged commit ead6732 into main Jul 17, 2026
3 checks passed
@p-x9
p-x9 deleted the codex/relative-list-location branch July 17, 2026 16:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants