-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Hasten macro parsing #68848
New issue
Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? # to your account
Hasten macro parsing #68848
Conversation
This is a hacky but easy change that gets some of the wins that #68836 would get. |
@bors try @rust-timer queue |
Awaiting bors try build completion |
⌛ Trying commit e30f495ecec1a30ac97215bee2107b4fdaa1a884 with merge 0c7ea93de45e21ba54a804998b0b7563386ba795... |
☀️ Try build successful - checks-azure |
Queued 0c7ea93de45e21ba54a804998b0b7563386ba795 with parent 002287d, future comparison URL. |
As expected, the perf results are excellent for |
I like this, the idea is pretty simple and I wouldn't even call it a hack. |
e30f495
to
2a13b24
Compare
The
The change is justified if the directory cloning is so relatively cheap that it is lost in the noise from the whole parser cloning. |
Parser cloning is very rare on this code path, so much so that there is no measurable benefit to making it cheaper. I previously made Does that help? I'm not sure how else to explain it. |
@petrochenkov are you happy to r+ this instead of @eddyb? |
Yes, r? @petrochenkov I left a couple of comments, r=me after addressing them. |
Currently, every iteration of the main loop in `generic_extension` instantiates a `Parser`, which is expensive because `Parser` is a large type. Many of those instantiations are only used immutably, particularly for simple-but-repetitive macros of the sort seen in `html5ever` and PR 68836. This commit initializes a single parser outside the loop, and then uses `Cow` to avoid cloning it except for the mutating iterations. This speeds up `html5ever` runs by up to 15%.
The previous commit wrapped `Parser` within a `Cow` for the hot macro parsing path. As a result, there's no need for the `Cow` within `Directory`, because it lies within `Parser`.
This is a small win, because `Failure` is much more common than `Success`.
2a13b24
to
6851f9a
Compare
I addressed the comments, and added a trivial commit fixing a typo in a variable name. @bors r=petrochenkov |
📌 Commit 2a13b24 has been approved by |
…=petrochenkov Hasten macro parsing r? @eddyb
…=petrochenkov Hasten macro parsing r? @eddyb
Rollup of 9 pull requests Successful merges: - #67642 (Relax bounds on HashMap/HashSet) - #68848 (Hasten macro parsing) - #69008 (Properly use parent generics for opaque types) - #69048 (Suggestion when encountering assoc types from hrtb) - #69049 (Optimize image sizes) - #69050 (Micro-optimize the heck out of LEB128 reading and writing.) - #69068 (Make the SGX arg cleanup implementation a NOP) - #69082 (When expecting `BoxFuture` and using `async {}`, suggest `Box::pin`) - #69104 (bootstrap: Configure cmake when building sanitizer runtimes) Failed merges: r? @ghost
☔ The latest upstream changes (presumably #69118) made this pull request unmergeable. Please resolve the merge conflicts. |
Something weird happened here. Somehow an old version of this branch got merged. I will have to put the orphaned changes in a separate PR. |
#69150 is the PR. |
…ochenkov Follow-up to rust-lang#68848 This PR contains some late changes to rust-lang#68848 that somehow didn't get included when that PR was merged in a roll-up. r? @petrochenkov
Rollup of 7 pull requests Successful merges: - #68129 (Correct inference of primitive operand type behind binary operation) - #68475 (Use a `ParamEnvAnd<Predicate>` for caching in `ObligationForest`) - #68856 (typeck: clarify def_bm adjustments & add tests for or-patterns) - #69051 (simplify_try: address some of eddyb's comments) - #69128 (Fix extra subslice lowering) - #69150 (Follow-up to #68848) - #69164 (Update pulldown-cmark dependency) Failed merges: r? @ghost
r? @eddyb