Open Bug 1834092 Opened 1 year ago Updated 2 months ago

Improve Performance of TranslationsDocument Mutation Observation

Categories

(Firefox :: Translations, task, P3)

task

Tracking

()

People

(Reporter: nordzilla, Unassigned)

References

(Blocks 1 open bug)

Details

At present, the mutation observer code behaves fairly eagerly:

https://searchfox.org/mozilla-central/source/toolkit/components/translations/content/translations-document.sys.mjs#268-286

This is not an issue for a majority of sites that do not have a lot of mutations on page load. However, websites like YouTube will cause a significant delay in page load when auto-translate is enabled:

https://share.firefox.dev/42IGRa1

In particular, we are seeing a lot of time spent in textContent and garbage collection:

https://share.firefox.dev/41M10L2

To improve performance on page load, we should consider options to debounce taking action on mutation observations.

We could explore doing this on a set time interval, or possibly once per requestedAnimationFrame.

We will need a way to aggregate and de-duplicate nodes from mutations to translate on the debounce. Using a Set<Node> may work, but there could exist edge cases where the Node is no longer on the page, or the node's parent is also in the set.

We can ensure that the translation is valid by deduplicating on the root-most Nodes.

Summary: Improve Performance of Translations Document Mutation Observation → Improve Performance of TranslationsDocument Mutation Observation
Priority: -- → P3
No longer blocks: 1820214
No longer blocks: fx-translation

Maybe this will help with the performance related to bug 1651969.

Yes, I believe that is the root cause for that perf issue.

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