Skip to content

[SymbolGraph] don't scan every available module for cross-import overlays #36303

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 3 commits into from
Mar 8, 2021

Conversation

QuietMisdreavus
Copy link
Contributor

Resolves rdar://74928853

When the symbol graph tool checks for cross-import overlays declared by the current module, it currently looks through all the available modules, and loads every module whose name begins with an underscore to check it. This can lead to a wildly inefficient situation if there are many large overlay modules in the SDK. In one situation the symbol graph tool tool two minutes on my machine for a module with only a handful of items in it, just because of the overlay module scan.

This PR changes this behavior to instead query the module itself for any overlay modules, the same way that SourceKit would. This speeds up that module's call to a fraction of a second, providing a three order-of-magnitude speedup to the call overall.

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@franklinsch
Copy link
Contributor

@swift-ci Please Build Toolchain macOS Platform


Success |= symbolgraphgen::emitSymbolGraphForModule(CIM, Options);
}
SmallVector<ModuleDecl *, 2> Overlays;
Copy link
Contributor

@franklinsch franklinsch Mar 5, 2021

Choose a reason for hiding this comment

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

Any specific reason for 2? Is it meant to be 32?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No specific reason, other than "i thought the template parameter was required". It looks like i can leave the template parameter out entirely and get a "reasonable default", so i'll do that.

Copy link
Contributor

Choose a reason for hiding this comment

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

TIL and I wish I’d known this years ago

@@ -260,16 +260,16 @@ int swift_symbolgraph_extract_main(ArrayRef<const char *> Args, const char *Argv
// don't need to print these errors.
CI.removeDiagnosticConsumer(&DiagPrinter);

for (const auto &ModuleName : VisibleModuleNames) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we still need to accumulate the VisibleModuleNames above? Maybe we should log what findDeclaredCrossImportOverlaysTransitive returns?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

As for logging, since we're printing the modules as we load them, i don't think it's 100% necessary to add more logging on top of that just to list the modules beforehand.

}
SmallVector<ModuleDecl *, 2> Overlays;
M->findDeclaredCrossImportOverlaysTransitive(Overlays);
for (const auto *OM : Overlays) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looks like we used to sort the overlays by name. Is this something we should do here as well? I'm not sure whether sorting was a requirement for us to produce correct SGFs.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The original use for VisibleModuleNames is for reporting to the user when the given module name wasn't found. The sorting was (as far as i know) just for ease of user experience when reading the module list. I can move the initialization and sorting back into that error branch so we don't hit that in the normal path at all.

@QuietMisdreavus
Copy link
Contributor Author

I've pushed a couple commits for the review comments.

@swift-ci Please smoke test

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please Build Toolchain macOS Platform

@QuietMisdreavus QuietMisdreavus force-pushed the QuietMisdreavus/better-overlay-search branch from 69109bc to 9717af8 Compare March 5, 2021 22:49
@QuietMisdreavus
Copy link
Contributor Author

QuietMisdreavus commented Mar 5, 2021

The toolchain build failed due to rdar://75096485. I've rebased the PR to pick up #36317.

@swift-ci Please build toolchain macOS platform

@QuietMisdreavus
Copy link
Contributor Author

@swift-ci Please smoke test

@swift-ci
Copy link
Contributor

swift-ci commented Mar 6, 2021

macOS Toolchain
Download Toolchain
Git Sha - 9717af8

Install command
tar -zxf swift-PR-36303-898-osx.tar.gz --directory ~/

@QuietMisdreavus
Copy link
Contributor Author

Linux CI seems to have failed on an icu test. Going to run it again in case it's a fluke...

@swift-ci Please smoke test Linux platform

@QuietMisdreavus
Copy link
Contributor Author

QuietMisdreavus commented Mar 8, 2021

Looks like i got hit by some test failures that were also happening on Friday morning. From what i can tell, the test in question has been reverted by now, so once more, with feeling...

@swift-ci Please smoke test Linux platform

@QuietMisdreavus QuietMisdreavus merged commit 2159908 into main Mar 8, 2021
@QuietMisdreavus QuietMisdreavus deleted the QuietMisdreavus/better-overlay-search branch March 8, 2021 20:05
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.

4 participants