-
Notifications
You must be signed in to change notification settings - Fork 17
Retain the dyld_shared_cache to which one belongs #238
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
Adds retention of dyld cache objects to avoid repeatedly re-mapping the same files and propagates parent FullDyldCache / main-cache references through created DyldCache and MachOFile instances.
- Passes DyldCache references into MachOFile initializers to retain and reuse mapped caches.
- Introduces internal linkage (_fullCache / _mainCache) plus helper APIs (cache(for:), subcache init) to navigate between main, sub, and full caches.
- Updates ObjC optimization helpers and subcache resolution to propagate cache references.
Reviewed Changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| ObjCHeaderInfoRO.swift | Adds cache parameter when constructing MachOFile to retain associated DyldCache. |
| DyldSubCacheEntry.swift | Uses new subcache initializer and propagates _fullCache. |
| MachOFile.swift | Adds cache/fullCache retention fields, new convenience init, and makes cache/fullCache properties public with lazy caching logic. |
| FullDyldCache.swift | Ensures created DyldCache instances point back to FullDyldCache; adds cache(for:) lookup. |
| DyldCache.swift | Adds retention of parent/full caches, new subcache init variant, and passes self when creating MachOFile instances. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| public var cache: DyldCache? { | ||
| if let _cache { return _cache } | ||
| if let fullCache { | ||
| return fullCache.cache(for: url) |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The result of fullCache.cache(for:) is not stored back into _cache, causing a new DyldCache instance to be produced on every access despite the stated goal of retaining caches. Assign the looked-up cache to _cache before returning to ensure reuse.
| return fullCache.cache(for: url) | |
| _cache = fullCache.cache(for: url) | |
| return _cache |
Sources/MachOKit/MachOFile.swift
Outdated
| if let _fullCache { return _fullCache } | ||
| if let _cache, | ||
| let _fullCache = _cache._fullCache { | ||
| return _cache._fullCache |
Copilot
AI
Oct 5, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This early return does not persist the discovered FullDyldCache into self._fullCache, so subsequent calls will recompute (or re-traverse) instead of using a cached reference. Set self._fullCache = _fullCache before returning to retain it.
| return _cache._fullCache | |
| self._fullCache = _fullCache | |
| return _fullCache |
…ence - Ensure _fullCache is set in _cache when initializing - Return _fullCache directly if available
DyldCacheorFullDyldCacheevery time to access the cache is inefficient.Foundation.FileHandlewas used for reading files, resulting in a structure that repeatedly performed seek and read operations.