Closed Bug 1811750 Opened 2 years ago Closed 1 year ago

Performance.mark/measure/clearMarks take a long time to execute

Categories

(Core :: DOM: Performance APIs, defect)

Firefox 110
defect

Tracking

()

RESOLVED FIXED
124 Branch
Performance Impact low
Tracking Status
firefox-esr115 --- fixed
firefox124 --- fixed

People

(Reporter: henry.fai.hang.chan, Assigned: alexical)

References

(Depends on 1 open bug)

Details

Attachments

(4 files)

User Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/110.0

Steps to reproduce:

Performance.mark/measure takes a long time to execute. Profiling shows that it takes up to 50% of the whole re-render when using vue with performance tracking turned on.

Attached image Call Tree
Attached image Market Chart

As per the marker chart, even though a large amount of markers are being set and unuset, it appears there are only 7 markers active at one point in time. Since vue is one of the more popular frameworks used by websites, it may be worth optimizing for it.

The Bugbug bot thinks this bug should belong to the 'Core::Performance' component, and is moving the bug to that component. Please correct in case you think the bot is wrong.

Component: Untriaged → Performance
Product: Firefox → Core
See Also: → 1373086
Component: Performance → DOM: Performance

The severity field is not set for this bug.
:fdoty, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(fdoty)

Placing this bug into triage prior to setting severity

Performance Impact: --- → ?
Flags: needinfo?(fdoty)

The severity field is not set for this bug.
:fdoty, could you have a look please?

For more information, please visit auto_nag documentation.

Flags: needinfo?(fdoty)

It would be great if you could upload the actual profile and put a link here! That will allow us to investigate more easily. As well as allow us to see the c++ portions of the stacks here.

Flags: needinfo?(henry.fai.hang.chan)

Awaiting a profile to review before setting severity

Flags: needinfo?(fdoty)

Closing as inactive waiting for profile.

Status: UNCONFIRMED → RESOLVED
Closed: 2 years ago
Resolution: --- → INACTIVE

The profile I've taken may have some sensitive info. Is there someone I can directly mail this file to?

Flags: needinfo?(henry.fai.hang.chan)
Status: RESOLVED → REOPENED
Ever confirmed: true
Flags: needinfo?(dothayer)
Resolution: INACTIVE → ---

Sorry for the delay! henryfhchan, could you email this to dothayer@mozilla.com?

Flags: needinfo?(dothayer) → needinfo?(henry.fai.hang.chan)

Just sent, thank you!

Flags: needinfo?(henry.fai.hang.chan)
Performance Impact: ? → low
Flags: needinfo?(dothayer)

Basically we were falling off a cliff where if we had a bunch of marks recorded
with a particular name, when trying to measure we would fill an array with all
of them only to return the last one. This just replaces that by iterating in
reverse and returning the first matching mark. Arguably we should be using a
hashmap or something here, but this is a quick and trivial improvement that I
think will resolve the reported issue.

Assignee: nobody → dothayer
Pushed by dothayer@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/d5c4672573a9 Eliminate redundant array filling in performance.measure r=sefeng
Status: REOPENED → RESOLVED
Closed: 2 years ago1 year ago
Resolution: --- → FIXED
Target Milestone: --- → 124 Branch

Henry, could you give this a try on the latest version of Nightly? I'm not sure if the patch resolved the performance problem you observed since I don't have a specific example page, but based on your profile I think it should.

Flags: needinfo?(dothayer) → needinfo?(henry.fai.hang.chan)

I'm still seeing clearPerformanceMark take a huge chunk of time on 124.0a1 (2024-01-26) (64-bit) (a412d893c38f632f34b44a9c5b3fd8cc30bb87be). I'll send you the updated stack trace.

Flags: needinfo?(henry.fai.hang.chan)
  • Performance.measure() has a drastic improvement such that it no longer appears in the profile. However, Performance.clearMarks() still takes up quite a significant chunk of time. This was tested on 124.0a1 (2024-01-26) (64-bit) on macOS mbp with commit a412d893c38f632f34b44a9c5b3fd8cc30bb87be.

An updated profile has been sent. Many thanks for your assistance!

Status: RESOLVED → REOPENED
Resolution: FIXED → ---
Summary: Performance.mark/measure takes a long time to execute → Performance.mark/measure/clearMarks take a long time to execute
Severity: -- → S4

Hi Alex -- YouTube seems to be running into this in ESR 115, possibly due to a recent change on their side to use the associated APIs more aggressively (or with redundant names?). They might work around it, but for now this is pretty painful for ESR users.

Here are two profiles that I just captured in ESR115, which show massive time (40 seconds / 85 seconds respectively) spent in Performance.measure():
https://share.firefox.dev/3AIlAUQ
https://share.firefox.dev/3AEXrOV

...vs. Firefox 128 release which spends barely any time (228 samples i.e. 0.228 seconds, over the whole profile) in Performance.measure
https://share.firefox.dev/3T3kHwr

Given how targeted the patch is and the potential perf wins, maybe worth nominating for uplifting to ESR?

Flags: needinfo?(dothayer)

(We've got word from YouTube folks that they're rolling back the change that made them trip over this, so that reduces the pressure here a bit, but still worth considering for uplift if it's a safe change that avoids a pitfall that sites are sometimes tripping over.)

Comment on attachment 9376160 [details]
Bug 1811750 - Eliminate redundant array filling in performance.measure r?baku

ESR Uplift Approval Request

  • If this is not a sec:{high,crit} bug, please state case for ESR consideration: This was producing substantial slowdowns on YouTube with a recent change they made. They rolled back their change, but this could be affecting other sites similarly.
  • User impact if declined: Slowness on sites which make heavy use of performance.measure
  • Fix Landed on Version: 124
  • Risk to taking this patch: Low
  • Why is the change risky/not risky? (and alternatives if risky): It's an incredibly small patch which has been live for many months now, and all it does is remove purely redundant work which makes no behavioral difference other than slowing the browser down.
Flags: needinfo?(dothayer)
Attachment #9376160 - Flags: approval-mozilla-esr115?

Resolving the bug and creating follow-ups for additional work, to simplify tracking.

Status: REOPENED → RESOLVED
Closed: 1 year ago1 year ago
Resolution: --- → FIXED
Depends on: 1915469

Comment on attachment 9376160 [details]
Bug 1811750 - Eliminate redundant array filling in performance.measure r?baku

Uplift approved for ESR 115. I am checking with QA if we have time to respin and revalidate our 115.15.0 build with this patch before we ship it next Tuesday.

Attachment #9376160 - Flags: approval-mozilla-esr115? → approval-mozilla-esr115+

This fix will ship in 115.16esr.

You need to log in before you can comment on or make changes to this bug.

Attachment

General

Creator:
Created:
Updated:
Size: