Skip to content
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

Speed-up HTML escaping by using equal sized entities #55

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

Kijewski
Copy link
Collaborator

@Kijewski Kijewski commented Jul 7, 2024

By using codepoint entities like '&'"&", we have a much smaller lookup table (58 bytes instead of 29× pointer size ~= 232 bytes). This makes the cache happy, and the benchmark run about ~20% faster.

$ cargo bench --bench escape
Escaping                time:   [3.4087 µs 3.4126 µs 3.4168 µs]
                        change: [-19.790% -19.580% -19.354%] (p = 0.00 < 0.05)
                        Performance has improved.

This PR is based on #53.

TODO:

  • fix all the expected outputs

By using codepoint entities like `'&'` → `"&rinja-rs#38;"`, we have a much
smaller lookup table (58 bytes instead of 29× pointer size ~= 232
bytes). This makes the cache happy, and the benchmark run about ~20%
faster.

```text
$ cargo bench --bench escape
Escaping                time:   [3.4087 µs 3.4126 µs 3.4168 µs]
                        change: [-19.790% -19.580% -19.354%] (p = 0.00 < 0.05)
                        Performance has improved.
```
@Kijewski Kijewski marked this pull request as ready for review July 7, 2024 22:54
@GuillaumeGomez
Copy link
Contributor

That's great, thanks!

@GuillaumeGomez GuillaumeGomez merged commit 8c856c5 into rinja-rs:master Jul 8, 2024
17 checks passed
@Kijewski Kijewski deleted the pr-five-chars branch July 8, 2024 13:12
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.

2 participants