Skip to content

Commit dfdd798

Browse files
authored
During test discovery, ignore Swift types in the Darwin/dyld shared cache. (#392)
This PR modifies the Darwin-specific implementation of runtime type enumeration such that types in Darwin's dyld shared cache are ignored. As of macOS Sonoma, there are approximately 300 images in the shared cache containing approximately 3,000 Swift types, none of which are reasonably expected to represent test declarations. We don't need to enumerate these types. Skipping them gets us a speedup of approximately 27% (according to my very unscientific measurements.) Images in the current process (including framework binaries) that come from the shared cache have the `MH_DYLIB_IN_CACHE` bit set in their Mach headers, so we can easily filter them out. ### Checklist: - [x] Code and documentation should follow the style of the [Style Guide](https://github.com/apple/swift-testing/blob/main/Documentation/StyleGuide.md). - [x] If public symbols are renamed or modified, DocC references should be updated.
1 parent 414cd10 commit dfdd798

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Sources/TestingInternals/Discovery.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,14 @@ static SWTMachHeaderList getMachHeaders(void) {
236236
objc_addLoadImageFunc([] (const mach_header *mh) {
237237
auto mhn = reinterpret_cast<SWTMachHeaderList::value_type>(mh);
238238

239+
// Ignore this Mach header if it is in the shared cache. On platforms that
240+
// support it (Darwin), most system images are containined in this range.
241+
// System images can be expected not to contain test declarations, so we
242+
// don't need to walk them.
243+
if (mhn->flags & MH_DYLIB_IN_CACHE) {
244+
return;
245+
}
246+
239247
// Only store the mach header address if the image contains Swift data.
240248
// Swift does not support unloading images, but images that do not contain
241249
// Swift code may be unloaded at runtime and later crash

0 commit comments

Comments
 (0)