-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Investigate allocations in Fact.toEvent: allocates a Pair for each comparison #21171
Comments
This code is wrapped by the This might be a good opportunity to measure that too as this will also execute synchronously and could block the following code. Question: is taking a profile good enough to understand this code or should we benchmark? |
In browsing around the app, I subjectively noticed that In the case of the awesomebar providers, each keystroke triggers 7 facts, which is 1.75ms summed in the best case (caveat: clock granularity) and 2.64ms in one case where I measured each call individually (caveat still applies). This isn't a user perceptible delay so I'm more concerned about this from a battery and memory perspective.
In 13 iterations of the track block, a median run through it is 0.66ms with the max as 1.09ms and min as 0.36ms (i.e. this doesn't seem to hit clock granularity). This seems to get called roughly as often as Then again we have no idea how much battery these use beyond "less work is better for battery" so it's difficult to measure the power use impact. However, they seem like relatively straight forward fixes so it might be worth it for a blind fix. |
wrt allocations, typing in the awesomebar produces a sin wave pattern: In the first screenshot, I typed "no no im figuring it out" and the memory went from ~144.3 MB to 167.6 MB and back down to 144.4 MB, and it continues to climb afterwards. This may not be directly related to the SummaryThere are three issues in this bug:
I'm guessing we should file these separately? They seem like they could be good |
I discovered the gradual increase was because the Gecko profiler was sampling because I accidentally left the profiler file in. However, without the gradual allocations, I was able to determine each keystroke allocates 0.2-0.3 MB of memory. |
To make the issues easier to understand, I changed this issue to an investigation issue and filed 3 follow-ups linked from #21171 (comment) |
Fact.toEvent
uses awhen
statement with 36 items to compare its value. For each value, it's comparing to a Pair:The
to
function is actually allocating a Pair for each item, each time this is called (i.e. we may allocate 35 times in the current code). It doesn't get optimized out: here's the bytecode for the first comparison:It's unclear how bad this is in practice: e.g. what the duration is for being called once, how many times it may be called in a row, if it's blocking the main thread, and if 35 Pairs (4.4 KiB?) will create a lot of churn in the GC.
┆Issue is synchronized with this Jira Task
The text was updated successfully, but these errors were encountered: