Add Fluent support for DOM console messages and start migrating strings from dom.properties
Categories
(Core :: DOM: Core & HTML, task)
Tracking
()
| Tracking | Status | |
|---|---|---|
| firefox163 | --- | fixed |
People
(Reporter: flod, Assigned: flod)
References
(Blocks 1 open bug)
Details
Attachments
(6 external files, 1 obsolete file)
dom.properties is one of the largest remaining legacy .properties files. This bug adds the infrastructure needed to report DOM console messages using Fluent, and migrates a first set of strings to validate it (ideally trying to cover edge cases).
Infrastructure:
- Add a Fluent-based
nsContentUtils::ReportToConsole, together withFormatFluentStringandFormatMaybeFluentString. This mirrors the existingdom.propertiessupport (FluentResourceFile/gFluentResourceFilesfollowPropertiesFile/gPropertiesFiles, cachedLocalizationobjects followsStringBundles). - Cache a separate en-US
Localizationfor documents that spoof English, since web-exposed messages (e.g. deprecation reports) must not leak the UI locale. - Support Fluent messages in
nsIGlobalObject::ReportToConsole, including from workers:ReportErrorToConsoleRunnableaccepts either aPropertiesFileor aFluentResourceFile, and messages are formatted on the main thread. - Add
SpecialPowers.formatFluentValue, so tests can compute expected messages (including bidi isolation marks) instead of hard-coding them.
Initial migrations (with a Fluent migration recipe so existing translations carry over):
- A first sample of
dom.propertiesstrings intodom/dom.ftl; URLs are also passed as arguments instead of being hard-coded in translations, which has always been hickey. PerformanceObserverwarnings (reported from both windows and workers).- SVG reference document warnings, mapped from their enum through a table so further migrations only require adding rows instead of changing code.
- A sample of deprecation warnings (
dom/deprecations.ftl). - The slow script dialog (
dom/dialogs.ftl) and the file input validation message (dom/form-validation.ftl).
Once this lands, remaining dom.properties strings can be migrated incrementally in follow-up bugs.
| Assignee | ||
Comment 1•26 days ago
|
||
I tried to measure performance of Fluent vs. .properties locally (macOS, en-US), comparing validationMessage for a required file input with a required text input.
Time
- First message from a Fluent file in a content process: 0.14–0.2 ms, mostly fixed setup. Each additional file: 0.06–0.14 ms, mostly parsing.
- Five files loaded in one process: 0.42 ms (1 message each), 0.52 ms (all of dom.properties split into 5 files), 0.76 ms (5 × 275 messages).
- After the first call there's no measurable difference from .properties (0.36 vs 0.32 µs per call), so frequently triggered warnings only pay the cold cost once per process.
Memory (change in heapAllocated)
- About 11 KB per Localization, plus roughly 7–10× the .ftl size for the parsed resource, in each content process that uses that file.
- All of dom.properties migrated into 5 files: about 360 KB per process that uses them all.
dom.propertiesuses about 0.3 KB per process, thanks to the shared-memory string bundles.
Takeaways
- The files in this bug would all be under 2 KB, so the cost is a few tens of KB, only in processes that trigger these messages.
- We should avoid having a single large file like we have with
dom.properties. Group messages by how often they're hit, so rarely used strings don't get loaded by most processes, while keeping in mind the ~11 KB fixed cost per file (avoid too many files). - Content processes have nothing like
SharedStringBundlefor Fluent.
| Assignee | ||
Comment 2•26 days ago
•
|
||
Following Claude's suggestion, tried with DMD (heap profiler).
DMD build on macOS (en-US), one content process. It loads the three files in my WIP for this bug, then repeats with form-validation.ftl padded to 277 messages (+37.5 KB).
| Allocation | Files in this bug | Padded | Cost |
|---|---|---|---|
Parsed AST (fluent_syntax) |
8.7 KB | 152.8 KB | ~3.8× file size |
| File contents | 3.8 KB | 51.8 KB | ~1.3× file size |
Bundle entries (add_resource) |
1.5 KB | 34.9 KB | ~120 B per message |
Bundle cache (ChunkyVec) |
24.1 KB | 24.1 KB | 8 KB per Localization |
Localization / generator |
1.2 KB | 1.1 KB | ~0.4 KB per Localization |
| Total | 39.3 KB | 264.6 KB |
Roughly 9 KB fixed per Localization + ~6× the .ftl size, in each content process that uses the file. Parsed resources stay cached in L10nFileSource until the process exits.
- Most of the fixed cost is unused:
fluent-fallback's bundle cache uses aChunkyVecwhose first chunk has room for 32 bundles (DEFAULT_CAPACITY), but aLocalizationnormally needs one or two. A smaller first chunk would save ~7 KB perLocalizationacross all of Firefox. - The AST and the entry map are ~80% of the per-byte cost, which lazy per-message parsing would avoid.
Will file a separate bug for the first part, the second is a much larger change.
| Assignee | ||
Updated•25 days ago
|
| Assignee | ||
Comment 3•25 days ago
|
||
Add Fluent-based nsContentUtils::ReportToConsole, FormatFluentString and
FormatMaybeFluentString, and migrate a few dom.properties strings to
dom/dom.ftl. URLs are now passed as arguments instead of being hard-coded in
translations.
The new code mirrors the existing dom.properties support in nsContentUtils:
FluentResourceFile and gFluentResourceFiles follow PropertiesFile and
gPropertiesFiles, the cached Localization objects follow sStringBundles
(including the cleanup in Shutdown()), and FormatFluentStringRunnable follows
FormatLocalizedStringRunnable to format messages for workers on the main
thread. Since a Localization's language is fixed when it's created, a separate
en-US instance is cached for documents that spoof English, as
txMozillaXSLTProcessor does.
Add SpecialPowers.formatFluentValue, so that tests can compute the expected
messages, including bidi isolation marks, instead of hard-coding them.
| Assignee | ||
Comment 4•25 days ago
|
||
Migrate the PerformanceObserver warnings, which are reported from both windows
and workers.
ReportErrorToConsoleRunnable now accepts either a PropertiesFile or a
FluentResourceFile, instead of adding a separate runnable for Fluent messages.
| Assignee | ||
Comment 5•25 days ago
|
||
Warnings identified by an enum are mapped to Fluent messages with a table, so
that migrating more of them only requires adding rows.
| Assignee | ||
Comment 6•25 days ago
|
||
Deprecation reports are exposed to web content, so they use en-US when English
is spoofed. They can be reported from workers, which relies on the console
relay added in part 2.
| Assignee | ||
Comment 7•25 days ago
|
||
This is preserving the current awkward & used to define the accesskey.
Moving this to an accesskey attribute would require adding C++ code to read the Fluent attribute,
a complex Fluent migration, and code to mark the character in the label.
This feels unnecessary given this is the only string still using this format for accesskeys,
and this dialog should only be relevant for non e10s builds (so hopefully short-lived).
| Assignee | ||
Comment 8•24 days ago
•
|
||
AI review highlighted an issue with BiDi markers (U+2068 and U+2069) that Fluent automatically adds around variables. That's a problem with DevTools, using a regex to make links active, and possibly for users copying and pasting error messages.
The two options on the table are:
- Create a second instance of L10nRegistry with BiDi isolation disabled (that's a built-in setting). Requires Rust and C++, although the code changes should be contained.
- Strip BiDi markers from the strings, and accept possible issues (it's not possible to differentiate the ones inserted by localizers from those introduced by Fluent). Turns our that both PushNotifications and CrashReportes are already doing that (example).
| Assignee | ||
Comment 9•24 days ago
•
|
||
I tried searching for an error message with and without markers, it definitely impacts results on GitHub (no results with markers), Bing (half the results). Based on this small sample, I think we need to remove them.
Bing: Ignoring unsupported entryTypes message (about half the results)
- Without marks: https://www.bing.com/search?q=Ignoring%20unsupported%20entryTypes%3A%20invalid.
- With marks: https://www.bing.com/search?q=Ignoring%20unsupported%20entryTypes%3A%20%E2%81%A8invalid%E2%81%A9.
GitHub issues: exact phrase "Ignoring unsupported entryTypes: paint"
- Without marks (109 issues): https://github.com/search?type=issues&q=%22Ignoring%20unsupported%20entryTypes%3A%20paint%22
- With marks (0 issues): https://github.com/search?type=issues&q=%22Ignoring%20unsupported%20entryTypes%3A%20%E2%81%A8paint%E2%81%A9%22
| Assignee | ||
Comment 10•24 days ago
|
||
I ended up writing a patch for L10nRegistry and a test, and discovered that the bot's finding was incorrect.
BiDi markers were put behind a pref in bug 1439018, and that pref is false in Gecko
https://searchfox.org/firefox-main/rev/fa1e90ea670c4234c61b65a05dc02032b9bcde03/intl/l10n/rust/fluent-ffi/src/bundle.rs#150-155
Updated•14 days ago
|
Updated•14 days ago
|
Updated•14 days ago
|
Updated•14 days ago
|
| Assignee | ||
Comment 12•14 days ago
|
||
The messages for invalid week and month values were looked up with keys that
don't exist in dom.properties (FormValidationInvalidWeek and
FormValidationInvalidMonth instead of FormValidationInvalidDateWeek and
FormValidationInvalidDateMonth), so these inputs had no message. They now
use the migrated Fluent messages.
The text lengths are passed as numbers, so that the messages can select
plural forms and format the numbers for the locale.
To avoid selecting a plural form for two numbers in the same message, the
text length messages only select one for the length limit, and show the
current length as "(current length: N)".
Updated•11 days ago
|
Updated•11 days ago
|
Updated•11 days ago
|
Updated•11 days ago
|
Updated•11 days ago
|
Updated•11 days ago
|
Comment 13•10 days ago
|
||
Note: This rearranges "spoof English"-sensitive code.
| Assignee | ||
Comment 14•10 days ago
|
||
(In reply to Henri Sivonen (:hsivonen) from comment #13)
Note: This rearranges "spoof English"-sensitive code.
Ideally this should be a no-op for that.
Comment 15•6 days ago
|
||
just a quick question: in Tor Browser we force users to restart the browser if they change app language. I know FF does this if the direction changes. We do this in TB regardless of direction change because some items e.g. MediaDocument.properties, dom.properties (to name some) are not updated live and require a restart. Would changing to Fluent resolve this?
| Assignee | ||
Comment 16•6 days ago
•
|
||
The .properties strings used by DOM code are cached in nsContentUtils for the lifetime of the process, so they don't pick up a language change. The Fluent replacement uses a Localization object that listens for intl:app-locales-changed and reloads its bundles, including in content processes, so messages migrated to Fluent should switch to the new language without a restart.
This bug only migrates a small part of dom.properties, but I'm hoping that migrating the remaining strings becomes a mechanical process.
MediaDocument.properties will keep requiring a restart until they're migrated too. appstrings.properties is even more complicated (see bug 1790187).
Comment 17•5 days ago
|
||
Comment 18•4 days ago
|
||
Comment 19•4 days ago
|
||
Backed out for causing mochitest failures @test_deprecated_fluent.html.
| Assignee | ||
Comment 20•4 days ago
|
||
Lovely, test fails only with --enable-xorigin-tests, it didn't fail locally or in the many try runs I've made.
Fixing and checking if other tests might be affected before pushing again.
Comment 21•4 days ago
|
||
Comment 22•4 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/61067d2baa45
https://hg.mozilla.org/mozilla-central/rev/0bd10a7867ee
https://hg.mozilla.org/mozilla-central/rev/6a51e00b0ac5
https://hg.mozilla.org/mozilla-central/rev/5802827a10f7
https://hg.mozilla.org/mozilla-central/rev/9985bd81d2ec
https://hg.mozilla.org/mozilla-central/rev/ca6078f43794
Comment 23•4 days ago
|
||
The backout is merged in central: https://hg.mozilla.org/mozilla-central/rev/271c0cf886156cbbaabe7c6d64c5ec27f9efb4a6
Comment 24•4 days ago
|
||
Comment 25•4 days ago
|
||
| bugherder | ||
https://hg.mozilla.org/mozilla-central/rev/e5cf1a613235
https://hg.mozilla.org/mozilla-central/rev/fe5a2c8cc886
https://hg.mozilla.org/mozilla-central/rev/311487d687ec
https://hg.mozilla.org/mozilla-central/rev/663a06a3aff4
https://hg.mozilla.org/mozilla-central/rev/ceb9541542af
https://hg.mozilla.org/mozilla-central/rev/473b81eadf38
Comment 26•3 days ago
|
||
This reverts commit 6a1979795b6a5f0c0016c857303b566fcb8f5e34.
Revert "Bug 2088603 - (part 5) Migrate the unresponsive script dialog to Fluent. r=dom-core-reviewers,fluent-reviewers,hsivonen,bolsson"
This reverts commit 444c3b88d3eb578ccda303f95f38257a2c66013c.
Revert "Bug 2088603 - (part 4) Add Fluent support for deprecation warnings and migrate the captureEvents, releaseEvents, mozGetAll and MathML mo accent ones. r=eemeli,dom-core-reviewers,fluent-reviewers,hsivonen,bolsson"
This reverts commit 0cb57bb8dcefda027b61ef417f9131ae830454dc.
Revert "Bug 2088603 - (part 3) Migrate the SVG reference loop and reference chain length warnings to Fluent. r=dom-core-reviewers,fluent-reviewers,hsivonen,bolsson"
This reverts commit dede564857cdf1195e78a1aa5109e5d08eaefd47.
Revert "Bug 2088603 - (part 2) Support Fluent messages in nsIGlobalObject::ReportToConsole for windows and workers, migrate PerformanceObserver warnings. r=dom-core-reviewers,fluent-reviewers,dom-worker-reviewers,hsivonen,bolsson,edenchuang"
This reverts commit 2e8df4ead5e12c19b7afb9cc4a4d717b42543d50.
Revert "Bug 2088603 - (part 1) Add Fluent support to nsContentUtils::ReportToConsole and migrate first warnings. r=eemeli,dom-core-reviewers,fluent-reviewers,geckoview-reviewers,hsivonen,bolsson,tthibaud"
This reverts commit 46b6b0b90f9055854849eddd5e09f659021dffa6.
Updated•3 days ago
|
Description
•