Skip to content

Member lookup macro expansion performance 5.9 #66267

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

DougGregor
Copy link
Member

@DougGregor DougGregor commented Jun 1, 2023

  • Explanation: When determining which type definitions and extensions need to have macros expanded to satisfy a member name lookup request, the name lookup code is iterating over all of the extensions of a given type and their members. When there are many extensions or members (e.g., thousands), the individually-cheap checks here cause significant compile-time performance problems. Memoize the member checks on a per-extension basis, and keep a separate (much smaller) list of those extensions that have any interesting macro behavior, so we don't need to walk the full list. On a source file containing 6,000 extensions of the same type, reduces compile time by ~25%, returning it to Swift 5.8 levels.
  • Scope: Moderate. Member name lookup is a fundamental operation used everywhere in the compiler, so the code changes will be exercised everywhere. The change to that code is fairly small and macro-centric.
  • Risk: Low; the code changed here only does any meaningful work when macros are present on the types or extensions, so it's unlikely to break anything not using macros even if it were wrong.
  • Issue: rdar://109543968
  • Original pull request: Member lookup macro expansion performance #66257

…d to

Keep track of which types/extensions have members that could be produced by
a macro expansion, including the names of those members. Use this to
avoid walking into extensions or type definitions to expand macros
when they don't have any related macros.
…hat matter

Keep track of those types and extensions that have any macro expansions,
so that when we need to check whether to expand macros to satisfy name
lookup, we only look through that list---rather than looking at every
extension again.

This improves compile times significantly for a source file with a
large number of extensions on a single type. However, there is still
much to do here.
@DougGregor DougGregor requested a review from a team as a code owner June 1, 2023 07:05
@DougGregor
Copy link
Member Author

@swift-ci please test

@DougGregor DougGregor merged commit 3a87a21 into swiftlang:release/5.9 Jun 2, 2023
@DougGregor DougGregor deleted the member-lookup-macro-expansion-performance-5.9 branch June 2, 2023 20:40
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