-
Notifications
You must be signed in to change notification settings - Fork 136
Make match_ignore_ascii_case more efficient, add ascii_case_insensitive_phf_map #122
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
Previously, the compiler would emit many `eq_ignore_ascii_case` calls, leading to code bloat and probably some slowness. Now, we pre-lowercase the input in a stack-allocated buffer then match exact strings. Hopefully, the optimizer can turn this into a static table and a loop.
Let users pass a `&foo` borrow. `&Cow<str>` can auto-deref to `&str`.
…f_map! We can do the lower-casing at compile time in a proc-macro. Note that `match_ignore_ascii_case!` still has that requirement, since it’s `macro_rules!` that generates a `match` expression.
* String patterns now need to be already ASCII lower-case * Input string is no longer implicitly borrowed, add `&` as needed.
r? @Manishearth, CC @nox
|
Update cssparser to 0.11 <!-- Please describe your changes on the following line: --> Depends on servo/rust-cssparser#122. --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [ ] `./mach build -d` does not report any errors - [ ] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. -->
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.
r=me looks good. Can't wait for proper proc macro support.
@bors-servo r=Manishearth |
📌 Commit 136c97a has been approved by |
Make match_ignore_ascii_case more efficient, add ascii_case_insensitive_phf_map This improves the performance of `match_ignore_ascii_case!` by replacing calls to `str::eq_ignore_ascii_case` with plain string equality. The input string is converted to ASCII lower-case once, using a stack allocated buffer. A `proc_macro_derive` is used internally to ensure that string patterns are already lower-case, and to computed the size of the buffer (the length of the longest pattern). This should improve runtime performance, it the amount of generated MIR or LLVM IR in release mode still looks proportional to the number of patterns, so this by itself won’t help much with the code bloat in `parse_color_keyword`. To deal with that, this PR also adds a `ascii_case_insensitive_phf_map!` macro that reuses the same stack-allocated buffer mechanism to lower-case an input string, and combines it with a [`phf`](https://github.com/sfackler/rust-phf) static hash map. The two macros are similar but make different treadoffs. PHF probably generates faster and less bloated code, but the map’s values need to be given as a string that contains Rust syntax, due to limitations of procedural macros in current stable Rust. On the other hand, generating a `match` expression allows using control flow statements like `return` or `continue` in its match arms. Fixes #115. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/122) <!-- Reviewable:end -->
💔 Test failed - status-travis |
@bors-servo retry Job timed out. |
Make match_ignore_ascii_case more efficient, add ascii_case_insensitive_phf_map This improves the performance of `match_ignore_ascii_case!` by replacing calls to `str::eq_ignore_ascii_case` with plain string equality. The input string is converted to ASCII lower-case once, using a stack allocated buffer. A `proc_macro_derive` is used internally to ensure that string patterns are already lower-case, and to computed the size of the buffer (the length of the longest pattern). This should improve runtime performance, it the amount of generated MIR or LLVM IR in release mode still looks proportional to the number of patterns, so this by itself won’t help much with the code bloat in `parse_color_keyword`. To deal with that, this PR also adds a `ascii_case_insensitive_phf_map!` macro that reuses the same stack-allocated buffer mechanism to lower-case an input string, and combines it with a [`phf`](https://github.com/sfackler/rust-phf) static hash map. The two macros are similar but make different treadoffs. PHF probably generates faster and less bloated code, but the map’s values need to be given as a string that contains Rust syntax, due to limitations of procedural macros in current stable Rust. On the other hand, generating a `match` expression allows using control flow statements like `return` or `continue` in its match arms. Fixes #115. <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/rust-cssparser/122) <!-- Reviewable:end -->
Not sure what homu is doing, https://travis-ci.org/servo/rust-cssparser/builds/205343338 is green. |
Update cssparser to 0.11 <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15735) <!-- Reviewable:end -->
Update cssparser to 0.11 <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15735) <!-- Reviewable:end -->
Update cssparser to 0.11 <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> <!-- Reviewable:start --> --- This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/servo/servo/15735) <!-- Reviewable:end -->
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172 --HG-- extra : subtree_source : https%3A//hg.mozilla.org/projects/converted-servo-linear extra : subtree_revision : b6f18aa92334574e0874e2ce8505c03f295c7d49
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172 UltraBlame original commit: 6fec46f1729153a0e230f4dac07ba776eebe6102
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172 UltraBlame original commit: 6fec46f1729153a0e230f4dac07ba776eebe6102
…p); r=emilio <!-- Please describe your changes on the following line: --> <s>Depends on https://github.com/servo/rust-cssparser/pull/122.</s> --- <!-- Thank you for contributing to Servo! Please replace each `[ ]` by `[X]` when the step is complete, and replace `__` with appropriate data: --> - [x] `./mach build -d` does not report any errors - [x] `./mach test-tidy` does not report any errors - [ ] These changes fix #__ (github issue number if applicable). <!-- Either: --> - [ ] There are tests for these changes OR - [ ] These changes do not require tests because _____ <!-- Pull requests that do not address these steps are welcome, but they will require additional verification as part of the review process. --> Source-Repo: https://github.com/servo/servo Source-Revision: 94e563e4d9292d7b19ce061e070cda358e822172 UltraBlame original commit: 6fec46f1729153a0e230f4dac07ba776eebe6102
This improves the performance of
match_ignore_ascii_case!
by replacing calls tostr::eq_ignore_ascii_case
with plain string equality. The input string is converted to ASCII lower-case once, using a stack allocated buffer. Aproc_macro_derive
is used internally to ensure that string patterns are already lower-case, and to computed the size of the buffer (the length of the longest pattern).This should improve runtime performance, it the amount of generated MIR or LLVM IR in release mode still looks proportional to the number of patterns, so this by itself won’t help much with the code bloat in
parse_color_keyword
.To deal with that, this PR also adds a
ascii_case_insensitive_phf_map!
macro that reuses the same stack-allocated buffer mechanism to lower-case an input string, and combines it with aphf
static hash map.The two macros are similar but make different treadoffs. PHF probably generates faster and less bloated code, but the map’s values need to be given as a string that contains Rust syntax, due to limitations of procedural macros in current stable Rust. On the other hand, generating a
match
expression allows using control flow statements likereturn
orcontinue
in its match arms.Fixes #115.
This change is