Closed
Bug 1355028
Opened 8 years ago
Closed 8 years ago
stylo: Add gtest microbenchmark for CSS parsing performance
Categories
(Core :: CSS Parsing and Computation, enhancement, P1)
Core
CSS Parsing and Computation
Tracking
()
RESOLVED
FIXED
mozilla55
| Tracking | Status | |
|---|---|---|
| firefox55 | --- | fixed |
People
(Reporter: SimonSapin, Assigned: SimonSapin)
References
(Blocks 2 open bugs)
Details
Attachments
(1 file)
No description provided.
| Comment hidden (mozreview-request) |
| Assignee | ||
Comment 2•8 years ago
|
||
These micro-benchmarks can be run with:
./mach gtest Stylo.*
Note that running `./mach build` is required after modifying example.css
Assignee: nobody → bobbyholley
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Assignee | ||
Updated•8 years ago
|
Attachment #8856411 -
Flags: review?(nfroyd)
Comment 6•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8856411 [details]
Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
https://reviewboard.mozilla.org/r/128366/#review130908
::: layout/style/test/gtest/StyloParsingBench.cpp:26
(Diff revision 4)
> + auto data = new URLExtraData(
> + NullPrincipalURI::Create(), nullptr, NullPrincipal::Create());
Do we want to free this value, since AFAICT from reading just this code, the servo side doesn't take ownership of the value?
::: layout/style/test/gtest/StyloParsingBench.cpp:44
(Diff revision 4)
> + auto stylesheet = new CSSStyleSheet(eAuthorSheetFeatures, CORS_NONE, RP_No_Referrer);
> + nsCSSParser parser(nullptr, stylesheet);
I *think* `nsCSSParser` takes ownership of the stylesheet, but it might be better to declare this as:
```
RefPtr<CSSStyleSheet> stylesheet = ...
```
just so it's clearer who's destroying what.
::: layout/style/test/gtest/generate_example_stylesheet.py:3
(Diff revision 4)
> + header = ("#define EXAMPLE_STYLESHEET \"%s\"" % css
> + .replace("\\", "\\\\")
> + .replace("\n", "\\n")
> + .replace("\"", '\\"')
For my own edification, why are we taking the generated file approach rather than using raw strings?
Attachment #8856411 -
Flags: review?(nfroyd) → review+
Comment 7•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8856411 [details]
Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
https://reviewboard.mozilla.org/r/128366/#review131218
r=me with those and Nathan's comments addressed.
::: layout/style/test/gtest/StyloParsingBench.cpp:22
(Diff revision 4)
> +
> +#define PARSING_REPETITIONS 100
> +
> +#ifdef MOZ_STYLO
> +
> +static void servo_parsing_bench() {
Nit: These names should be camel-cased.
::: layout/style/test/gtest/StyloParsingBench.cpp:28
(Diff revision 4)
> + for (int i = 0; i < PARSING_REPETITIONS; i++) {
> + Servo_StyleSheet_FromUTF8Bytes(
> + nullptr, nullptr, &css, eAuthorSheetFeatures, data
> + ).Consume();
> + }
It would be interesting to measure whether the results are basically identical between this approach and one where we call Servo_StyleSheet_FromUTF8Bytes once with the string chars repeated 100 times. Might be worth measuring and leaving a comment to that effect?
Attachment #8856411 -
Flags: review?(bobbyholley) → review+
| Assignee | ||
Comment 8•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8856411 [details]
Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
https://reviewboard.mozilla.org/r/128366/#review130908
> Do we want to free this value, since AFAICT from reading just this code, the servo side doesn't take ownership of the value?
Xidorn tells we this was a use-after-free (because the stylesheet would take a RefPtr of it, and when dropped free it since the ref count was 1) and that using "RefPtr<URLExtraData> data = …;" should fix it, I’ll do that.
> For my own edification, why are we taking the generated file approach rather than using raw strings?
I used a raw string literal at some point before submitting a patch, but even then the header file was generated with Python from a CSS file. The details of the CSS file are not that interesting, when modifying it one would typically replace it entirely with a different stylesheet from some website, not edit something in the middle.
With a raw string literal I couldn’t use `#define` because of newlines, so I had something like `const nsLiteralCString = NS_LITERAL_CSTRING(…)`. Now I can use the same `#define` with both `NS_LITERAL_CSTRING` and `NS_LITERAL_STRING`, the latter converting to UTF-16 at compile-time.
| Assignee | ||
Comment 9•8 years ago
|
||
| mozreview-review-reply | ||
Comment on attachment 8856411 [details]
Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
https://reviewboard.mozilla.org/r/128366/#review131218
> It would be interesting to measure whether the results are basically identical between this approach and one where we call Servo_StyleSheet_FromUTF8Bytes once with the string chars repeated 100 times. Might be worth measuring and leaving a comment to that effect?
I tried it (using `css * 100` in Python and removing the C++ loop) and measured no detectable difference. (The variation between runs without changing the code was greater.)
Comment 10•8 years ago
|
||
(In reply to Simon Sapin (:SimonSapin) from comment #9)
> Comment on attachment 8856411 [details]
> Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
>
> https://reviewboard.mozilla.org/r/128366/#review131218
>
> > It would be interesting to measure whether the results are basically identical between this approach and one where we call Servo_StyleSheet_FromUTF8Bytes once with the string chars repeated 100 times. Might be worth measuring and leaving a comment to that effect?
>
> I tried it (using `css * 100` in Python and removing the C++ loop) and
> measured no detectable difference. (The variation between runs without
> changing the code was greater.)
Ok, that's a very nice indication that we don't have a lot of per-stylesheet overhead beyond what's actually in the sheet. Worth writing a comment to that effect.
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Comment hidden (mozreview-request) |
| Assignee | ||
Comment 14•8 years ago
|
||
| mozreview-review | ||
Comment on attachment 8856411 [details]
Bug 1355028 - stylo: Add gtest microbenchmarks for CSS parsing performance.
https://reviewboard.mozilla.org/r/128366/#review131334
::: layout/style/test/gtest/StyloParsingBench.cpp:44
(Diff revisions 6 - 7)
>
> static void GeckoParsingBench() {
> + // Don’t use NS_LITERAL_STRING to work around
> + // "fatal error C1091: compiler limit: string exceeds 65535 bytes in length"
> + // https://msdn.microsoft.com/en-us/library/f27ch0t1.aspx
> + NS_ConvertUTF8toUTF16 css(NS_LITERAL_CSTRING(EXAMPLE_STYLESHEET));
This adds to the measured time, but only once outside of the "repeat a 100 times" loop.
Updated•8 years ago
|
Assignee: bobbyholley → simon.sapin
Priority: -- → P1
| Comment hidden (mozreview-request) |
Comment 16•8 years ago
|
||
Pushed by bholley@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/7b3007db548b
stylo: Add gtest microbenchmarks for CSS parsing performance. r=bholley,froydnj
Comment 17•8 years ago
|
||
| bugherder | ||
Status: NEW → RESOLVED
Closed: 8 years ago
Resolution: --- → FIXED
Target Milestone: --- → mozilla55
You need to log in
before you can comment on or make changes to this bug.
Description
•