-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Fix macro parser quadratic complexity in small repeating groups #52145
Conversation
For a fuller description of the performance issue fixed by this: rust-lang#51754 (comment)
(rust_highfive has picked a reviewer for you, use r? to override) |
It would be cool to see the results of a perf run :) |
After re-reading this a couple times, I think autocorrect got you there =P |
Oh, yeah. Autoincorrect rather... I edited, but I forgot it doesn't send emails. |
@bors try I don't know that we'll see much from it, but we can try. |
Fix macro parser quadratic complexity in small repeating groups Observed in #51754, and more easily demonstrated with the following: ```rust macro_rules! stress { ($($t:tt)+) => { }; } fn main() { stress!{ a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a // ... 65536 copies of "a" total ... a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a } } ``` which takes 50 seconds to compile prior to the fix and <1s after. I hope this has a visible impact on the compile times for real code. (I think it is most likely to affect incremental TT munchers that deal with large inputs, though it depends on how they are written) For a fuller description of the performance issue: #51754 (comment) --- There is no test (yet) because I'm not sure how easily to measure this for regressions.
☀️ Test successful - status-travis |
@rust-timer build 257d854 |
Success: Queued 257d854 with parent 0e6b713, comparison URL. |
Performance... regressed? This is just dropping something earlier, so all I can imagine is:
|
Fairly certain that the measurements are just noise. |
+/- a few percent seems to "just happen" sometimes, yeah |
@ExpHP I think adding a regression test to the perf benchmark suite would be appropriate, no @Mark-Simulacrum ? |
src/libsyntax/ext/tt/macro_parser.rs
Outdated
@@ -696,10 +696,17 @@ pub fn parse( | |||
} else { | |||
return Failure(parser.span, token::Eof); | |||
} | |||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just curious, why put this in an else
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Short answer:
To satisfy (oops, see next comment)dropck
.
Long answer:
I primarily saw two options here:
Drop eof_items
at the beginning of the one branch that is currently affected by the drop
. -- This had the disadvantage that future refactorings could easily introduce similar performance regressions (possibly under different conditions).
Drop eof_items
as soon as possible. -- This required splitting the large if {} else if {} else if {} ...
into two. I saw this as the lesser of two evils, despite the following disadvantages:
eof_items
must be awkwardly dropped inside anelse
, since it was moved in theif
branch.- It takes a bit of careful reading to realize that the
if
branch unconditionally diverges, especially now that it has anelse
branch. For this reason, I added the assertion two lines below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oops. Right after posting that I decided to double-check on the playground, and it turns out that move analysis is in fact smart enough that the else
is not necessary.
That, and now that I look more closely, the if
branch here doesn't actually even move eof_items
.
@bors r+ |
📌 Commit 191e76c has been approved by |
Agreed that a regression test would be good. |
After rerunning tests locally I'm going to push another commit to get rid of the (I will also remove the assertion, which was originally added because I thought the |
local test failed on some |
@bors r=nikomatsakis |
📌 Commit 0467ae0 has been approved by |
⌛ Testing commit 0467ae0 with merge dd6e0358baae473ce9d0b10c6dd729780bf8a10c... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1 similar comment
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
Fix macro parser quadratic complexity in small repeating groups Observed in #51754, and more easily demonstrated with the following: ```rust macro_rules! stress { ($($t:tt)+) => { }; } fn main() { stress!{ a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a // ... 65536 copies of "a" total ... a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a a } } ``` which takes 50 seconds to compile prior to the fix and <1s after. I hope this has a visible impact on the compile times for real code. (I think it is most likely to affect incremental TT munchers that deal with large inputs, though it depends on how they are written) For a fuller description of the performance issue: #51754 (comment) --- There is no test (yet) because I'm not sure how easily to measure this for regressions.
☀️ Test successful - status-appveyor, status-travis |
Observed in #51754, and more easily demonstrated with the following:
which takes 50 seconds to compile prior to the fix and <1s after.
I hope this has a visible impact on the compile times for real code. (I think it is most likely to affect incremental TT munchers that deal with large inputs, though it depends on how they are written)
For a fuller description of the performance issue: #51754 (comment)
There is no test (yet) because I'm not sure how easily to measure this for regressions.