Slow load and long delay before search field can be interacted with on https://scouts.org.uk
Categories
(Core :: CSS Parsing and Computation, defect, P2)
Tracking
()
| Performance Impact | medium |
People
(Reporter: davehunt, Unassigned)
Details
(Keywords: perf:responsiveness)
Updated•7 years ago
|
Comment 1•7 years ago
|
||
After load typing in the search bar also janks
https://perfht.ml/2AFyNvM
Looks like time is being spent in Stylo.
Comment 2•7 years ago
•
|
||
From the profile, it's probably the searchPseudoElements function in https://raw.githubusercontent.com/FortAwesome/Font-Awesome/master/js/all.js.
Also, it looks like it's doing it periodically, which is not cool.
Indeed, they have:
<script> FontAwesomeConfig = { searchPseudoElements: true }; </script>
On the source.
The function is doing very dumb stuff, like querying the style of all pseudo-elements in the page. For reference:
function searchPseudoElements(root) {
if (!IS_DOM) return;
var end = perf.begin('searchPseudoElements');
disableObservation(function () {
toArray(root.querySelectorAll('*')).filter(function (n) {
return n.parentNode !== document.head && !~TAGNAMES_TO_SKIP_FOR_PSEUDOELEMENTS.indexOf(n.tagName.toUpperCase()) && !n.getAttribute(DATA_FA_PSEUDO_ELEMENT) && (!n.parentNode || n.parentNode.tagName !== 'svg');
}).forEach(function (node) {
[':before', ':after'].forEach(function (pos) {
var children = toArray(node.children);
var alreadyProcessedPseudoElement = children.filter(function (c) {
return c.getAttribute(DATA_FA_PSEUDO_ELEMENT) === pos;
})[0];
var styles = WINDOW.getComputedStyle(node, pos);
var fontFamily = styles.getPropertyValue('font-family').match(FONT_FAMILY_PATTERN);
var fontWeight = styles.getPropertyValue('font-weight');
if (alreadyProcessedPseudoElement && !fontFamily) {
// If we've already processed it but the current computed style does not result in a font-family,
// that probably means that a class name that was previously present to make the icon has been
// removed. So we now should delete the icon.
node.removeChild(alreadyProcessedPseudoElement);
} else if (fontFamily) {
var content = styles.getPropertyValue('content');
var prefix = ~['Light', 'Regular', 'Solid', 'Brands'].indexOf(fontFamily[1]) ? STYLE_TO_PREFIX[fontFamily[1]] : FONT_WEIGHT_TO_PREFIX[fontWeight];
var iconName = byUnicode(prefix, toHex(content.length === 3 ? content.substr(1, 1) : content)); // Only convert the pseudo element in this :before/:after position into an icon if we haven't
// already done so with the same prefix and iconName
if (!alreadyProcessedPseudoElement || alreadyProcessedPseudoElement.getAttribute(DATA_PREFIX) !== prefix || alreadyProcessedPseudoElement.getAttribute(DATA_ICON) !== iconName) {
if (alreadyProcessedPseudoElement) {
// Delete the old one, since we're replacing it with a new one
node.removeChild(alreadyProcessedPseudoElement);
}
var extra = blankMeta.extra;
extra.attributes[DATA_FA_PSEUDO_ELEMENT] = pos;
var abstract = makeInlineSvgAbstract(_objectSpread({}, blankMeta, {
icons: {
main: findIcon(iconName, prefix),
mask: emptyCanonicalIcon()
},
prefix: prefix,
iconName: iconName,
extra: extra,
watchable: true
}));
var element = DOCUMENT.createElement('svg');
if (pos === ':before') {
node.insertBefore(element, node.firstChild);
} else {
node.appendChild(element);
}
element.outerHTML = abstract.map(function (a) {
return toHtml(a);
}).join('\n');
}
}
});
});
});
end();
}
Furthermore they're observing all the changes in the page, including attributes, so each time an attribute changes they redo this process.
mo.observe(observeMutationsRoot, { // observeMutationsRoot == document.body
childList: true,
attributes: true,
characterData: true,
subtree: true
});
You can see the performance difference if you do the following on the console:
var s = performance.now(); document.querySelectorAll("*").forEach(e => { getComputedStyle(e, "::before").fontFamily; getComputedStyle(e, "::after").fontFamily; }); console.log(performance.now() - s)
In FF that takes 50ms ms, in Blink that takes about 20ms the first time, 12-ish later on.
I know the reason for that, and it's that we don't store useless pseudo-element styles to save memory, so when we get asked for them we need to recompute them.
For example, if I do the following to inhibit that memory optimization:
var s = document.createElement("style"); s.innerText = `*::before, *::after { display: inherit; content: inherit; }`; document.body.appendChild(s);
Now running the snippet above takes half the time it originally took. We also have the same optimization for display: none subtrees, which is harder to inhibit.
I'm not sure that performance difference is enough to explain the massive jank, there may be something else going on... Digging a bit more, putting a similar mutation observer on the root, the mutation records we get is for the DOM in the "partners" swiper, which is changing under a timer to animate it.
So there's about 300 mutation records per second, and we're recomputing those styles over and over in order to avoid storing them because they're useless. That's sad :(.
Inhibiting that memory optimization using the trick I posted above makes the page roughly as usable as browsing with Chromium, but of course with a memory usage penalty.
Comment 3•7 years ago
|
||
And the TL;DR is that I don't know what we should do about this. We can remove the memory optimization I guess, but that would be very unfortunate.
Comment 4•7 years ago
|
||
If we want to fix this, an alternative would probably be to cache somewhere when it's queried via DOM API?
Comment 5•7 years ago
|
||
I'm not sure that'd help. That'd be doing twice the work, which is basically what we're doing now.
Updated•7 years ago
|
| Reporter | ||
Updated•4 years ago
|
Updated•4 years ago
|
Comment 6•11 months ago
|
||
Tested recently on Win and Mac, current version - works for me. No issues seen in a profile, page loads quickly. please re-open this issue if it continues.
Description
•