Closed
Bug 1466529
Opened 7 years ago
Closed 7 years ago
Stylo is malloc heavy when parsing property values for style.foo = "bar";
Categories
(Core :: CSS Parsing and Computation, defect, P2)
Core
CSS Parsing and Computation
Tracking
()
Tracking | Status | |
---|---|---|
firefox63 | --- | fixed |
People
(Reporter: smaug, Assigned: u480271)
References
(Blocks 1 open bug)
Details
Attachments
(1 file)
Our style.foo = "bar"; handling seems to be a lot slower (2.5x) than in Blink,
at least in .color = "some valid value" case.
A testcase I've used for profiling is
https://bugzilla.mozilla.org/attachment.cgi?id=8982654
"withoutmutationobserver" part is perhaps the most valid part for this bug.
13% seems to be malloc/free + 9% locks around malloc/free
I'm not familiar with Stylo code, but could we optimize things like
https://searchfox.org/mozilla-central/rev/292d295d6b084b43b70de26a42e68513bb7b36a3/servo/ports/geckolib/glue.rs#3543
which shows up in the profile.
Could we use more stack allocation? Reuse objects?
Reporter | ||
Comment 1•7 years ago
|
||
And when we need to clone DeclarationBlock (if there are mutation event listeners or so), cloning is very malloc heavy.
Could we have 1 item cache for DeclarationBlocks or something?
Reporter | ||
Comment 2•7 years ago
|
||
Comment 3•7 years ago
|
||
This week I'm going to be in a profiling training in Paris and this kind of test-case could come handy ;)
Flags: needinfo?(emilio)
Comment 4•7 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #2)
> https://perfht.ml/2JrVGsc
Olli, was this build a --enable-release build? I'm somewhat surprised to see some stuff not getting inlined there.
Flags: needinfo?(bugs)
Reporter | ||
Comment 6•7 years ago
|
||
oh, wait, perhaps it was nightly. Let me reprofile.
Reporter | ||
Comment 7•7 years ago
|
||
https://perfht.ml/2JuKeMr this at least is Nightly. Still showing similar memory issues.
Updated•7 years ago
|
Whiteboard: [qf] → [qf:f64][qf:p1]
Updated•7 years ago
|
Whiteboard: [qf:f64][qf:p1] → [qf:p1:f64]
Updated•7 years ago
|
Priority: -- → P2
Comment hidden (mozreview-request) |
withoutmutationobserver post MiscContainer caching: https://perfht.ml/2uM2sAn
Assignee: nobody → dglastonbury
Reporter | ||
Comment 10•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266046
::: dom/base/nsAttrValue.cpp:69
(Diff revision 1)
> + }
> + } else if (sMiscContainerCache.compareExchange(nullptr, aCont)) {
> + return;
> + }
> +
> + // We raced with somebody else setting the cache; delete container.
...or there was a cache already.
(nothing 'raced' in that case, I'd say)
::: dom/base/nsAttrValueInlines.h:125
(Diff revision 1)
> void Cache();
> void Evict();
> +
> +protected:
> + /** Reset to initial empty container */
> + void Reset() {
{ should be on its own line
Attachment #8994446 -
Flags: review?(bugs) → review+
Comment 11•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266050
::: dom/base/nsAttrValue.cpp:41
(Diff revision 1)
>
> +/* static */ MiscContainer*
> +nsAttrValue::AllocMiscContainer()
> +{
> + MiscContainer* cont = nullptr;
> + if (MOZ_LIKELY(!IsInServoTraversal())) {
Why do you need this? You should be able to assert `NS_IsMainThread()`, we don't set attributes OMT, only the `style` attribute serialization, which given it's a declaration block should already have a misc container.
Comment 12•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266052
::: dom/base/nsAttrValue.cpp:41
(Diff revision 1)
>
> +/* static */ MiscContainer*
> +nsAttrValue::AllocMiscContainer()
> +{
> + MiscContainer* cont = nullptr;
> + if (MOZ_LIKELY(!IsInServoTraversal())) {
Note that SMIL _may_ set attributes when `IsInServoTraversal()` is true, IIRC, but that always happens on the main thread.
Reporter | ||
Comment 13•7 years ago
|
||
All the stylo-code is somewhat hairy, that either we need to be consistent and handle alloc/dealloc when stylo is running, or assert hard.
Comment 14•7 years ago
|
||
(In reply to Olli Pettay [:smaug] from comment #13)
> All the stylo-code is somewhat hairy, that either we need to be consistent
> and handle alloc/dealloc when stylo is running, or assert hard.
Yeah, the only place where we need to handle this is the serialization of the style attribute. Other than that everything should assert NS_IsMainThread.
Flags: needinfo?(emilio)
Reporter | ||
Comment 15•7 years ago
|
||
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
I guess this requires stylo peer review, given its unusual integration here with DOM code.
Attachment #8994446 -
Flags: review+
Assignee | ||
Comment 16•7 years ago
|
||
Thanks Olli. I'll follow up with Emilio.
Comment hidden (mozreview-request) |
Comment 18•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266280
::: dom/base/nsAttrValueInlines.h:126
(Diff revision 2)
> void Evict();
> +
> +protected:
> + /** Reset to initial empty container */
> + void Reset()
> + {
Hmm, this is a bit too much of a generic name given it doesn't free the resources it would have...
Not that the destructor would assert a lot more, but maybe instead of this we should just do:
```
cont->~MiscContainer();
new (cont) MiscContainer();
```
On the only caller?
Attachment #8994446 -
Flags: review?(emilio) → review+
Assignee | ||
Comment 19•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266538
::: dom/base/nsAttrValueInlines.h:126
(Diff revision 2)
> void Evict();
> +
> +protected:
> + /** Reset to initial empty container */
> + void Reset()
> + {
I like not adding a new function!
Comment hidden (mozreview-request) |
Comment hidden (mozreview-request) |
Comment 22•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266594
::: dom/base/nsAttrValue.cpp:55
(Diff revision 4)
> +
> +/* static */ void
> +nsAttrValue::DeallocMiscContainer(MiscContainer* aCont)
> +{
> + MOZ_ASSERT(NS_IsMainThread());
> + if (!aCont) return;
nit: use braces, please, and move return to its own line:
```
if (!aCont) {
return;
}
```
Assignee | ||
Comment 23•7 years ago
|
||
mozreview-review |
Comment on attachment 8994446 [details]
Bug 1466529 - P1: Cache MiscContainer to avoid malloc/free churn.
https://reviewboard.mozilla.org/r/259000/#review266598
::: dom/base/nsAttrValue.cpp:55
(Diff revision 4)
> +
> +/* static */ void
> +nsAttrValue::DeallocMiscContainer(MiscContainer* aCont)
> +{
> + MOZ_ASSERT(NS_IsMainThread());
> + if (!aCont) return;
But, so ugly...
Comment hidden (mozreview-request) |
Comment 25•7 years ago
|
||
Pushed by dglastonbury@mozilla.com:
https://hg.mozilla.org/integration/autoland/rev/0fe9aa9f75aa
P1: Cache MiscContainer to avoid malloc/free churn. r=emilio,smaug
Comment 26•7 years ago
|
||
bugherder |
Status: ASSIGNED → RESOLVED
Closed: 7 years ago
status-firefox63:
--- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla63
Updated•3 years ago
|
Performance Impact: --- → P1
Whiteboard: [qf:p1:f64]
You need to log in
before you can comment on or make changes to this bug.
Description
•