Skip to content

Only call getsectiondata() once per image. #734

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

Merged
merged 6 commits into from
Sep 26, 2024

Conversation

grynspan
Copy link
Contributor

@grynspan grynspan commented Sep 26, 2024

This PR improves the performance of test discovery by only calling getsectiondata() once per loaded image instead of twice. It also refactors the C++ platform-specific enumerator function to take a new structure, SWTSectionBounds, instead of multiple arguments. This lets us use a C++ range-for-loop (for (const auto& record : sectionBounds)) instead of a raw C for-loop, reduces register traffic on Windows, and is all around a bit more object-oriented (which I hope is an improvement, yeah?)

A non-scientific comparison at my desk shows that, before the change, cold test discovery on macOS took an average of 0.0376 seconds. After the change, the average was 0.0217 seconds for an approximate 1.73x speedup.

Checklist:

  • Code and documentation should follow the style of the Style Guide.
  • If public symbols are renamed or modified, DocC references should be updated.

This PR improves the performance of test discovery by only calling
`getsectiondata()` once per loaded image instead of twice. It also refactors the
C++ platform-specific enumerator function to take a new structure,
`SWTSectionBounds`, instead of multiple arguments. This lets us use a C++
range-for-loop (`for (const auto& record : sectionBounds)`) instead of a raw C
for-loop, reduces register traffic on Windows, and is all around a bit more
object-oriented (which I hope is an improvement, yeah?)

A non-scientific comparison at my desk shows that, before the change, **cold**
test discovery on macOS took an average of 0.0376 seconds. After the change,
the average was 0.0217 seconds for an approximate 1.73x speedup.
@grynspan grynspan added enhancement New feature or request darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support performance Performance issues labels Sep 26, 2024
@grynspan grynspan self-assigned this Sep 26, 2024
@grynspan
Copy link
Contributor Author

@swift-ci test

@@ -392,27 +416,27 @@ static void enumerateTypeMetadataSections(const SectionEnumerator& body) {
// Look in all the loaded modules for Swift type metadata sections and store
// them in a side table.
//
// This two-step process is less algorithmically efficient than a single loop,
// but it is safer: the callback will eventually invoke developer code that
// This two-step process is more complicated to read than a single loop would
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Technically it's O(n) either way, so it's not algorithmically more complex, but it is longer code.

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan
Copy link
Contributor Author

@swift-ci test

#else
using SWTMachHeaderList = SWTVector<const mach_header *>;
#endif

/// Get a copy of the currently-loaded Mach headers list.
Copy link
Contributor

Choose a reason for hiding this comment

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

Any of these docs need to be updated to reflect the new "section bounds" instead of "headers lists" terminology?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I'll do a quick pass before I merge.

@grynspan
Copy link
Contributor Author

@swift-ci test

@grynspan grynspan merged commit eed68e7 into main Sep 26, 2024
3 checks passed
@grynspan grynspan deleted the jgrynspan/getsectiondata-once branch September 26, 2024 20:27
@grynspan grynspan added this to the Swift 6.1 milestone Sep 26, 2024
@grynspan grynspan added the discovery 🔎 test content discovery label Mar 12, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
darwin 🍎 macOS, iOS, watchOS, tvOS, and visionOS support discovery 🔎 test content discovery enhancement New feature or request performance Performance issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants