gecko-dev/devtools
Razvan Caliman c85367f9d5 Bug 1623988 - Extract CSS variables used in a CSS declaration for quick reference r=jdescottes
Inspecting pages with many CSS variables makes DevTools Inspector very slow.
For example, try to inspect an element on [youtube.com](https://www.youtube.com/).

One of the stylesheets loaded by youtube.com contains more than 7800 CSS rules (it's 55K lines long). Some of them specify a very large number of CSS variable delcarations on `:root` which will be inherited by all nodes on the page. This is a perf bottleneck for DevTools.
{F2150398}

Whenever an element is selected, its matching CSS declarations show in the Rules view. If the node inherits CSS variables, for **each declaration**, the Rules view checks if the [variables apply to the current declaration](https://searchfox.org/mozilla-central/rev/2bfe3415fb3a2fba9b1c694bc0b376365e086927/devtools/client/inspector/rules/models/element-style.js#403-408,417,424).

This among other expensive operations which are repeated for each declaration. But for CSS variables, it's particularly slow given the frequent [checks with a regular expression](https://searchfox.org/mozilla-central/rev/2bfe3415fb3a2fba9b1c694bc0b376365e086927/devtools/client/inspector/rules/utils/utils.js#292-295) to verify if a CSS declaration's value includes any references to a given CSS variable name.

This patch introduces new functionality. When a `TextProperty` (aka CSS declaration model) is created on the client, the names of CSS variables found in its value are extracted ahead of time into a `Set`. Whenever we want to check if the declaration uses a certain CSS variable name, we check against this pre-compiled list instead of verifying the string value every time. For high volume checks, like the ones done by the `ElementStyle`, this approach proves significantly faster.

Profile without this patch: https://bit.ly/2Yd7khD
Profile with this patch: https://bit.ly/3aMhJTZ

There are still many optimizations that can be done, but the `hasCSSVariable()` method is no longer a performance bottleneck.

Differential Revision: https://phabricator.services.mozilla.com/D73062
2020-05-14 18:20:00 +00:00
..
client Bug 1623988 - Extract CSS variables used in a CSS declaration for quick reference r=jdescottes 2020-05-14 18:20:00 +00:00
docs Bug 1637983 - Replace Slack links by Matrix in documentation. r=jdescottes. 2020-05-14 14:57:15 +00:00
platform Bug 1620542 - Automatically fix ESLint errors in .eslintrc.js files. r=mossop 2020-03-07 10:09:44 +00:00
server Bug 1555057 - Show the related Add-on for blocked resources. r=bomsy 2020-05-14 08:51:29 +00:00
shared Bug 1555057 - Show the related Add-on for blocked resources. r=bomsy 2020-05-14 08:51:29 +00:00
startup Bug 1617246 - Always consult objdirs for symbols. r=gregtatum 2020-05-11 19:52:53 +00:00
.eslintrc.js Bug 1625495 - Remove devtools/shared/client folder r=daisuke,ochameau,nchevobbe 2020-03-31 08:36:29 +00:00
.eslintrc.mochitests.js Bug 1622328 - add license info to all eslintrc files r=Standard8,webcompat-reviewers,miketaylr 2020-03-19 13:47:51 +00:00
.eslintrc.xpcshell.js Bug 1622328 - add license info to all eslintrc files r=Standard8,webcompat-reviewers,miketaylr 2020-03-19 13:47:51 +00:00
CODE_OF_CONDUCT.md
moz.build Bug 1599027 - Remove http inspector doc. r=Honza. 2019-11-26 08:43:59 +00:00
templates.mozbuild
tsconfig.json Bug 1603351 - Add a tsconfig.json file in devtools root folder. r=gregtatum. 2019-12-16 15:21:03 +00:00