Reuse cached file handles with MachOKit backing identities - #32
Merged
Conversation
Use MachOKit's file handle identity as the cache key so related MachOFile and DyldCache wrappers reuse the same mapped file. Reuse FullDyldCache's resolved URL list when opening concatenated cache files.
Contributor
There was a problem hiding this comment.
Pull request overview
Updates MachOKit/swift-fileio and adjusts mapped-file caching so multiple MachOKit wrapper objects that share the same underlying backing identity reuse the same cached MemoryMappedFile/ConcatenatedMemoryMappedFile handles, reducing redundant opens/mappings.
Changes:
- Bump MachOKit to
0.52.0and swift-fileio to0.14.0(plus updated lockfiles). - Key mapped-file caches by MachOKit
fileHandleIdentity(SPI) instead of wrapper object identity forMachOFile/DyldCache/FullDyldCache. - Reuse
FullDyldCache.urlswhen opening concatenated cache files.
Reviewed changes
Copilot reviewed 5 out of 6 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| Sources/MachOObjCSection/Extension/MachOFile+.swift | Switch MemoryMappedFile cache key to MachOKit backing identity. |
| Sources/MachOObjCSection/Extension/DyldCache+.swift | Introduce shared FileHandleHolder keyed by FileHandleIdentity for dyld cache mappings. |
| Sources/MachOObjCSection/Extension/FullDyldCache+.swift | Key concatenated-cache mapping by backing identity and reuse urls list. |
| Package.swift | Update dependency minimum versions (MachOKit, swift-fileio). |
| Package.resolved | Refresh resolved graph for updated dependencies. |
| Benchmarks/Package.resolved | Refresh benchmark resolved graph for updated dependencies. |
Comments suppressed due to low confidence (1)
Sources/MachOObjCSection/Extension/MachOFile+.swift:26
- This change is performance/behavioral (cache key now uses MachOKit’s
fileHandleIdentity). There are existing XCTest suites, but there’s no assertion that two wrappers sharing the same backing identity actually reuse the sameMemoryMappedFileinstance. Adding a focused unit test would help prevent regressions (e.g.,XCTAssertTrue(a.fileHandle === b.fileHandle)for two wrappers known to share identity).
var fileHandle: File {
FileHandleHolder.shared.fileHandle(
for: fileHandleIdentity,
initialize: {
try! .open(url: url, isWritable: false)
}
)
💡 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
MachOFileandDyldCachewrappers reuse the same cached handle.FullDyldCache.urlswhen opening concatenated cache files instead of resolving the subcache URLs again.Why
The caches were keyed by individual wrapper objects. Multiple wrappers backed by the same MachOKit file handle could therefore create separate mapped-file cache entries and reopen the same file.
Using MachOKit's backing identity aligns the cache lifetime and reuse boundary with the underlying handle while keeping the identity itself separate from filesystem path identity.
Impact
This reduces redundant file opens and mappings for related MachOKit wrappers. There are no public API changes in MachOObjCSection.
Validation
git diff --cached --checkswift testcompleted the build and the tests observed before interruption passed. The full suite was stopped because existing dump tests emit extremely large Objective-C output and run for an extended period.