nsTextFragment::SetTo() could be faster by allocating less often

RESOLVED FIXED in Firefox 59

Status

()

Core
DOM
P2
normal
RESOLVED FIXED
10 months ago
5 months ago

People

(Reporter: Ehsan, Assigned: m_kato)

Tracking

(Blocks: 1 bug)

unspecified
mozilla59
Points:
---
Dependency tree / graph

Firefox Tracking Flags

(firefox59 fixed)

Details

Attachments

(2 attachments)

(Reporter)

Description

10 months ago
This function currently allocates memory extremely inefficiently.  Here are some examples:

 * It allocates memory even if the requested length in the same type of buffer already allocated is less than what we already have allocated.
 * It doesn't have nsTArray-like exponential growth with a cap behavior, so in cases where it's called in a loop it ends up allocating/copying too much, and can end up having quadratic behavior.
 * For performance reasons, it may be worth considering keeping the fragment wide once it is allocated as wide instead of freeing it and reallocating it as narrow if SetTo() is called later with a narrow string.

Updated

10 months ago
Priority: -- → P1
(Reporter)

Comment 1

10 months ago
Note that this is a super small part of the profiles currently.  I'm keeping the bug open hoping that after we shave off enough of the cost from other places here, this starts to become a significant part of the cost in profiles...

Updated

9 months ago
Depends on: 1393232
Per comment 1, seems this doesn't need to be P1 for 57 release...
Seems P2-ish.
Priority: P1 → P2
(Assignee)

Comment 5

5 months ago
bug 1375910's micro benchmark can improve 10%+ by WIP.

Comment 6

5 months ago
Created attachment 8940695 [details] [diff] [review]
text_setto.diff

Just modified the WIP a bit to ensure we don't keep too large string buffers alive.
remote: View your change here:
remote:   https://hg.mozilla.org/try/rev/fa39c24cb00c7c0bc8ddcc298f7daafe80a1c6a5
remote: 
remote: Follow the progress of your build on Treeherder:
remote:   https://treeherder.mozilla.org/#/jobs?repo=try&revision=fa39c24cb00c7c0bc8ddcc298f7daafe80a1c6a5
remote: recorded changegroup in replication log in 0.064s
Attachment #8940695 - Flags: review?(m_kato)
(Assignee)

Updated

5 months ago
Attachment #8940695 - Flags: review?(m_kato) → review+

Updated

5 months ago
Assignee: nobody → m_kato

Comment 7

5 months ago
Pushed by opettay@mozilla.com:
https://hg.mozilla.org/integration/mozilla-inbound/rev/a0cf29a08c3d
nsTextFragment::SetTo() could be faster by allocating less often, p=makoto,smaug, r=makoto,smaug
https://hg.mozilla.org/mozilla-central/rev/a0cf29a08c3d
Status: NEW → RESOLVED
Last Resolved: 5 months ago
status-firefox59: --- → fixed
Resolution: --- → FIXED
Target Milestone: --- → mozilla59
You need to log in before you can comment on or make changes to this bug.