Skip to content

Reuse cached file handles with MachOKit backing identities - #32

Merged
p-x9 merged 2 commits into
mainfrom
feature/file-handle-identity
Jul 23, 2026
Merged

Reuse cached file handles with MachOKit backing identities#32
p-x9 merged 2 commits into
mainfrom
feature/file-handle-identity

Conversation

@p-x9

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

Copy link
Copy Markdown
Owner

Summary

  • Update MachOKit to 0.52.0.
  • Key mapped-file caches by MachOKit's backing file-handle identity so related MachOFile and DyldCache wrappers reuse the same cached handle.
  • Reuse FullDyldCache.urls when 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 --check
  • swift test completed 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.

p-x9 added 2 commits July 23, 2026 01:50
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.
@p-x9
p-x9 requested a review from Copilot July 23, 2026 17:42
@p-x9
p-x9 marked this pull request as ready for review July 23, 2026 17:42

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

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.0 and swift-fileio to 0.14.0 (plus updated lockfiles).
  • Key mapped-file caches by MachOKit fileHandleIdentity (SPI) instead of wrapper object identity for MachOFile / DyldCache / FullDyldCache.
  • Reuse FullDyldCache.urls when 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 same MemoryMappedFile instance. 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.

Comment thread Sources/MachOObjCSection/Extension/MachOFile+.swift
@p-x9
p-x9 merged commit 0a860dd into main Jul 23, 2026
3 checks passed
@p-x9
p-x9 deleted the feature/file-handle-identity branch July 23, 2026 17:47
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