Add benchmark for a style-heavy document - #642
Merged
Merged
Conversation
The suite left the CSS path almost entirely unmeasured. ecmascript.html has no styled element at all and google.html has eight of 309, yet sanitizing a style attribute costs far more per byte than sanitizing ordinary markup: the new 63 KB document takes 22.4 ms and allocates 15.5 MB, against 7.0 ms and 6.0 MB for a google.html two and a half times its size. Per byte that is roughly six times the cost, and it was invisible. HTML email is where that case really arises, since mail clients strip stylesheets and templates inline everything instead. email.html is generated rather than taken from a real campaign, so nothing third-party is vendored in, but its shape is calibrated against a real responsive template: about 45% of elements carry a style attribute averaging 3.3 declarations, drawn from the property mix that template actually uses. Values differ per element so the CSS parser cannot cache its way to a number no real document would produce, and background-image: url(...) is kept to a minority because the reference template has none inline - over-representing it would flatter any change aimed at URL handling. Two benchmarks, because <style> is not an allowed tag by default and the tag is therefore dropped before its content is looked at: SanitizeEmail measures the inline path as a caller gets it out of the box, and SanitizeEmailWithStyleSheets allows the tag so that SanitizeStyleSheets, and the CSS parsing and regex work behind it, are on the measured path. The difference between them is 3.3 ms and 1.2 MB for 8.1 KB of CSS.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #642 +/- ##
=======================================
Coverage 93.47% 93.47%
=======================================
Files 6 6
Lines 1119 1119
Branches 152 152
=======================================
Hits 1046 1046
Misses 47 47
Partials 26 26 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added a CSS-heavy benchmark
Cherry picked from #639 without any optimizations to code
The existing benchmarks barely exercise CSS:
ecmascript.html: no styled elementsgoogle.html: only 8 styled elementsCSS sanitization is relatively expensive, so a generated
email.htmlbenchmark was added to represent HTML email, where inline styles are common.Despite being much smaller than
google.html, the email benchmark takes roughly 3× longer and allocates over 2× as much, showing how expensive the CSS path can be.Two benchmarks are included:
SanitizeEmail— normal inline-style sanitizationSanitizeEmailWithStyleSheets— also enables<style>so stylesheet sanitization is measured