Closed Bug 1412319 Opened 2 years ago Closed 2 years ago

Investigate allRulesHaveSource slowness


(DevTools :: Inspector: Rules, defect, P2)



(Not tracked)



(Reporter: pbro, Unassigned)


(Blocks 1 open bug)



(1 file)

Attached is a perf.html profile I recorded on a local FF58 build.
In that build, I have added a custom user-timing that shows how much time the selection of a new node using the context-menu item takes.
It makes it quite easy to investigate what code runs during that time and what takes the longest.

Among these things, the function allRulesHaveSource seems to be taking quite a long time.

Here is the function:

Its role is to make sure all rules inside a given stylesheet actually have an authored source.
This is useful to detect whether some dynamic changes to the stylesheet were done using the CSS Object-Model API.

To do this, the function loops over each and every rule in the stylesheet (sheet.cssRules), and calls DOMUtils.getRelativeRuleLine on them.

Let's investigate the impact this is having and how to make it faster.
Here is a test:
- open
- select 10 different elements on the page
- measure the time each of these take
- remove the highest value
- and calculate the average.

On my (powerful) machine:

-> 430ms on average.

I then added an early `return true` at the top of the allRulesHaveSource function and re-did the same test:

-> 326ms on average.

So there are some wins to be have by optimizing this function.
See Also: → 1415940
In bug 1415940, we discovered this check no longer works correctly in Stylo mode.

In Stylo, `DOMUtils.getRelativeRuleLine` can still return a value even with CSSOM changes.
Priority: -- → P2
Flags: needinfo?(bugs)
Another website where allRulesHaveSource has a significant impact on the inspector initialization. 
After bug 1415940, allRulesHaveSource is gone, and the new API is much faster - so this can probably be closed now.
Thanks for the ping, let's close this now that the method has been removed. Did a quick profile again on the sites mentioned here and couldn't see any significant slowdown.
Closed: 2 years ago
Flags: needinfo?(bugs)
Resolution: --- → DUPLICATE
Duplicate of bug: 1415940
Product: Firefox → DevTools
You need to log in before you can comment on or make changes to this bug.