Skip to content

[InterfaceFile] Improve flag extraction from interface file #72093

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

cachemeifyoucan
Copy link
Contributor

Improve the version/flags extract from interface file by moving away from using Regex and limiting the search to the beginning of the file.

Switch away from Regex will give 5-10% improvement in time and instruction counts, and limiting the search lines can save a lot of time if the swiftinterface is large. For example, the extract time for Swift stdlib is 10x faster after the patch.

@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test

@nkcsgexi nkcsgexi requested a review from tshortli March 5, 2024 20:42
StringRef prefix) {
StringRef line;
unsigned lineCount = 0;
const unsigned maxLine = 10;
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a bit of a shame that we need a magic constant here, I wonder if there's anything we can do to make sure this is a valid precondition. Maybe asserting on textual interface printing or verification that this always holds true?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Let me see what I can do. I am not really eager to land this since I don't see this really impact performance in any significant way in a real world compilation but more performance is always good.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ok, I revisited this patch. Remove the magic number but only parses the first comment block instead.

I don't know what is a good place to implement a diagnostics though. Ideally it should be interface compilation and model comments in swift AST?

@tshortli
Copy link
Contributor

tshortli commented Mar 5, 2024

Looks reasonable, I'm not surprised that regex is a bottleneck here.

@cachemeifyoucan cachemeifyoucan force-pushed the eng/PR-faster-flag-extraction branch from bb6852e to a0e1c35 Compare April 18, 2024 22:59
@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test

@cachemeifyoucan cachemeifyoucan force-pushed the eng/PR-faster-flag-extraction branch from a0e1c35 to e92e66f Compare April 19, 2024 00:21
@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test

@cachemeifyoucan cachemeifyoucan force-pushed the eng/PR-faster-flag-extraction branch from e92e66f to b296013 Compare October 31, 2024 18:17
@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test

Improve the version/flags extract from interface file by moving away
from using Regex and limiting the search to the beginning of the file.

Switch away from Regex will give 5-10% improvement in time and
instruction counts, and limiting the search lines can save a lot of time
if the swiftinterface is large. For example, the extract time for Swift
stdlib is 10x faster after the patch.

Current strategey for limiting the line to search is by only parsing the
first comment block.
@cachemeifyoucan cachemeifyoucan force-pushed the eng/PR-faster-flag-extraction branch from b296013 to 8150fb0 Compare October 31, 2024 19:46
@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test

@cachemeifyoucan
Copy link
Contributor Author

@swift-ci please smoke test windows platform

@cachemeifyoucan cachemeifyoucan merged commit f288e39 into swiftlang:main Nov 1, 2024
3 checks passed
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