Closed Bug 1837078 Opened 1 year ago Closed 1 year ago

Refactor the Translations actor to remove memory footprint, and increase performance

Categories

(Firefox :: Translations, task, P1)

task

Tracking

()

RESOLVED FIXED
116 Branch
Tracking Status
firefox116 --- fixed

People

(Reporter: gregtatum, Assigned: gregtatum)

References

(Regressed 1 open bug)

Details

Attachments

(17 files)

48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review
48 bytes, text/x-phabricator-request
Details | Review

We need to move more work to the parent and lazy load everything in the child. In addition, we need to memoize everything in the parent so that work isn't done over and over on every page load.

This will hopefully address Bug 1836039 and Bug 1836467.

Since there is an await in the code, this handler became racy. Checking
the id ensures that only the most recent event is used. This was causing
some automated tests to fail when I changed the underlying
implementation.

Depends on D180468

This probably isn't too important, but Set.prototype.has is faster
than Array.prototoype.includes. The setters are probably more
expensive, but those aren't in hot paths. This change would only be
noticeable if the lists got longer, but even with only a few items in
the list, .has is faster.

Depends on D180470

This will have some eslint errors, and not run correctly, but it makes
the following diff much clearer for what is new code, and what is moved
code.

Depends on D180479

Any JS code (including comments) gets loaded into content process memory
for every single content process that is loaded. This patch tries to
reduce this burden as much as possible by moving things into either the
TranslationsParent, or into lazily loaded modules in the child.

This patch also changes the engine caching logic to only allow 1 engine
cache at a time. I was struggling porting over the existing cache to this
strategy, and this felt like a much simpler solution.

Depends on D180481

This also removes some dead code around clearing the language tag, and
properly lists the required events for the TranslationsChild. I guess
that code was never even running, and I tests it manually after removing
it.

Depends on D180848

Pushed by gtatum@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/e06f6601bd46 Fix race condition in the translations button event handler; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/267c8b09163a Correct incorrect test assertions in translations test; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/6dbd9581b622 Micro-optimize translation prefs; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/2c11cf745b67 Break out the engine payload loading into a method with profiler markers; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/e2c376ce8337 Simplify the isRestrictedPage to use the scheme; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/b698293af16a Cache the language id model record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/847a4fccbb63 Cache translation model records; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/07dd77f0fa2b Cache the language id wasm record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/b04e59be41cd Cache the bergamot wasm record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/406ab7121048 Cache the language pairs in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/c30b954c1f48 Use the content principal information in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/47593c037f71 Naively split out engine files into separate modules; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/2d423bdf9b9a Move logic for identifying languages into a lazy loaded module; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/464b57aa51cb Remove as much logic as possible from the TranslationsChild; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/c0776a2926de Detect when the Translations actor is destroyed during async work; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/72c0e162e5a8 Do not report errors when the language id engine fails to download; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/e7efea009a6c Do not get language id payload if the page is hidden; r=nordzilla
Flags: needinfo?(gtatum)
Pushed by gtatum@mozilla.com: https://hg.mozilla.org/integration/autoland/rev/9ecac650e6fa Fix race condition in the translations button event handler; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/cda00c714446 Correct incorrect test assertions in translations test; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/f90402ee929c Micro-optimize translation prefs; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/33c5c63fb8be Break out the engine payload loading into a method with profiler markers; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/177dbec0fb98 Simplify the isRestrictedPage to use the scheme; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/b727be4caaa6 Cache the language id model record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/9d2c3ef9ebf3 Cache translation model records; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/ba3465f86326 Cache the language id wasm record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/5268b542e1c6 Cache the bergamot wasm record in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/facbc44bba8c Cache the language pairs in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/4efd0a919db3 Use the content principal information in the TranslationsParent; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/7b9f3e6ac0ed Naively split out engine files into separate modules; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/7da78f67d716 Move logic for identifying languages into a lazy loaded module; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/3df1f1fd5e1c Remove as much logic as possible from the TranslationsChild; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/ccd6c3d67650 Detect when the Translations actor is destroyed during async work; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/a503e6e1f6f4 Do not report errors when the language id engine fails to download; r=nordzilla https://hg.mozilla.org/integration/autoland/rev/a0a479ff9216 Do not get language id payload if the page is hidden; r=nordzilla
Regressions: 1838515
Blocks: 1820214
Regressions: 1838934
Regressions: 1911890
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: