Closed Bug 1690634 Opened 3 years ago Closed 3 years ago

Remove well-known and static string atom instance

Categories

(Core :: JavaScript Engine, task, P3)

task

Tracking

()

RESOLVED FIXED
87 Branch
Tracking Status
firefox87 --- fixed

People

(Reporter: arai, Assigned: arai)

References

(Blocks 1 open bug)

Details

Attachments

(21 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
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

If all operations on well-known/static ParserAtomEntry pointer outside of ParserAtomsTable can be moved inside ParserAtomTable (bug 1689892), we can remove well-known/static ParserAtomEntry instances and instead use only TaggedParserAtomIndex as reference to them.

so that:

  • reduce rodata size
  • reduce startup cost for initializing the well-known table
  • enable adding more well-known/static
    • bug 1689434 (length-3 or more static strings)
    • make all atoms in self-hosted.js well-known

for static strings, the content can be encoded directly in the TaggedParserAtomIndex, so we don't need extra space.
for well-known, we'll need string constant in addition to atom index, to retrieve the content,
but that can be shared between VM well-known atoms or other static string constant.

Thinking a bit more about the merit:

ParserAtomEntry consists of:

  • HashNumber hash_
  • uint32_t length_
  • uint32_t flags_
  • trailing chars

even if we remove the entry instance, we need hash and the equivalent of trailing chars.
So, 8 bytes (length and flags) can be definitely reduced for each atom.

then, for well-known atoms, we already have const char js_FOO_str[];, so that can be shared.
https://searchfox.org/mozilla-central/rev/927e525f481a93a8f63d27a78ae6201e42b1b1fb/js/src/vm/JSAtom.cpp#220-222

bug 1689434 experiment proved that we can have TaggedParserAtomIndex without ParserAtomEntry instance.
the problem there were:

  • cannot statically calculate/allocate hash
  • atomization in toExistingJSAtom call

for well-known and length-1/2 case, we already calculate/allocate hash, and toExistingJSatom doesn't touch ParserAtomEntry instance but just returns from VM side's table,
so this should work.

Assignee: nobody → arai.unmht
Status: NEW → ASSIGNED

https://treeherder.mozilla.org/jobs?repo=try&revision=8934f21512c29261e32a08e0490a4049f89ad881

the patch doesn't yet dedup well-known atoms' string in frontend and js_FOO_str.
I hoped compiler can do that automatically, but maybe I should explicitly point the same string.

maybe we can move the WellKnownStringInfo in the patch out of frontend, and use that also from JSAtom.cpp
WellKnownStringInfo also contains hash, so JSRuntime::initializeAtoms can use that info to skip hash calculation on runtime

Here's the plan:

  1. Rewrite length-1/2 cases not to retrieve ParserAtom, but construct necessary info (content, length) in place
  2. Add WellKnownAtomInfo that holds (content, length, hash) for each well-known atoms
  3. Use WellKnownAtomInfo array to populate WellKnownParserAtoms::wellKnownMap_
  4. Rewrite well-known atom case not to retrieve ParserAtom, but use WellKnownAtomInfo
  5. Remove WellKnownParserAtoms_ROM and WellKnownParserAtoms's pointer fields
  6. Dedup js_*_str and WellKnownAtomInfo content
  7. Rewrite JSAtom common names initialization to use WellKnownAtomInfo array, with pre-calculated hash

WellKnownAtomInfo can be used also from JSAtom initialization later, so the
definition is placed in vm/WellKnownAtom.h, and also WellKnownAtomId is moved
there.

Depends on D104607

The result of size reduction

file before after diff
js shell 40,429,520 40,365,856 -63,664
x86_64 dmg 77,814,414 77,743,517 -70,897
XUL 161,242,216 161,193,856 -48,360
Attachment #9202212 - Attachment description: Bug 1690634 - Part 20: Use pre-calculated has in JSAtom common name initialization. → Bug 1690634 - Part 20: Use pre-calculated hash in JSAtom common name initialization.
Attachment #9202198 - Attachment description: Bug 1690634 - Part 6: Add length-1/2-specific path for ParserAtomsTable::isIndex. → Bug 1690634 - Part 6: Add length-1/2-specific path for ParserAtomsTable::isIndex. r=nbp!
Attachment #9202208 - Attachment description: Bug 1690634 - Part 16: Add WellKnownAtomInfo and use it in WellKnownParserAtoms::wellKnownMap_ and ParserAtomsTable::{dump,dumpCharsNoQuote}. → Bug 1690634 - Part 16: Add WellKnownAtomInfo and use it in WellKnownParserAtoms::wellKnownMap_ and ParserAtomsTable::{dump,dumpCharsNoQuote}. r=nbp!
Attachment #9202209 - Attachment description: Bug 1690634 - Part 17: Use GetWellKnownAtomInfo in ParserAtomsTable methods. → Bug 1690634 - Part 17: Use GetWellKnownAtomInfo in ParserAtomsTable methods. r=nbp!
Attachment #9202210 - Attachment description: Bug 1690634 - Part 18: Remove WellKnownParserAtoms_ROM. → Bug 1690634 - Part 18: Remove WellKnownParserAtoms_ROM. r=nbp!
Attachment #9202211 - Attachment description: Bug 1690634 - Part 19: Move js_*_str to WellKnownAtom.h. → Bug 1690634 - Part 19: Move js_*_str to WellKnownAtom.h. r=nbp!
Attachment #9202212 - Attachment description: Bug 1690634 - Part 20: Use pre-calculated hash in JSAtom common name initialization. → Bug 1690634 - Part 20: Use pre-calculated hash in JSAtom common name initialization. r=nbp!
Attachment #9202213 - Attachment description: Bug 1690634 - Part 21: Pre-calculate hash for symbol-related common names. → Bug 1690634 - Part 21: Pre-calculate hash for symbol-related common names. r=nbp!
Pushed by arai_a@mac.com:
https://hg.mozilla.org/integration/autoland/rev/218bb88bba9d
Part 1: Use range-specific methods. r=nbp
https://hg.mozilla.org/integration/autoland/rev/1c3cdfd28aff
Part 2: Do not reteieve atom entry for length-1/2 in ParserAtomsTable::length. r=nbp
https://hg.mozilla.org/integration/autoland/rev/0449ae9ec529
Part 3: Add ParserAtomsTable::{getLength1Content,getLength2Content} methods and use in ParserAtomsTable::{dump,dumpCharsNoQuote}. r=nbp
https://hg.mozilla.org/integration/autoland/rev/a8abd8e27509
Part 4: Add length-1/2-specific path for ParserAtomsTable::isIdentifier. r=nbp
https://hg.mozilla.org/integration/autoland/rev/8118bd961f9c
Part 5: Add length-1/2-specific path for ParserAtomsTable::isExtendedUnclonedSelfHostedFunctionName. r=nbp
https://hg.mozilla.org/integration/autoland/rev/6e986649b078
Part 6: Add length-1/2-specific path for ParserAtomsTable::isIndex. r=nbp
https://hg.mozilla.org/integration/autoland/rev/8bf00cffdeba
Part 7: Add length-1/2-specific path for ParserAtomsTable::toNumber. r=nbp
https://hg.mozilla.org/integration/autoland/rev/218133df75d4
Part 8: Add length-1/2-specific path for ParserAtomsTable::toNewUTF8CharsZ. r=nbp
https://hg.mozilla.org/integration/autoland/rev/e3c635019f2a
Part 9: Add length-1/2-specific path for ParserAtomsTable::toPrintableString. r=nbp
https://hg.mozilla.org/integration/autoland/rev/d85cd571f708
Part 10: Add length-1/2-specific path for ParserAtomsTable::toQuotedString. r=nbp
https://hg.mozilla.org/integration/autoland/rev/c73eb9133e56
Part 11: Add length-1/2-specific path for ParserAtomsTable::appendTo. r=nbp
https://hg.mozilla.org/integration/autoland/rev/833782d13263
Part 12: Add length-1/2-specific path for ParserAtomsTable::isModuleExportName. r=nbp
https://hg.mozilla.org/integration/autoland/rev/74cbe3f3c730
Part 13: Remove TaggedParserAtomIndex variant of getParserAtom. r=nbp
https://hg.mozilla.org/integration/autoland/rev/b2ba7e3b9245
Part 14: Move dumpCharsNoQuote for length-1/2 into separate static function, to use from stencil dump. r=nbp
https://hg.mozilla.org/integration/autoland/rev/52dd05ae7c18
Part 15: Remove ParserAtomsTable::{getLength1Static,getLength2Static}. r=nbp
https://hg.mozilla.org/integration/autoland/rev/d80f85078a7f
Part 16: Add WellKnownAtomInfo and use it in WellKnownParserAtoms::wellKnownMap_ and ParserAtomsTable::{dump,dumpCharsNoQuote}. r=nbp
https://hg.mozilla.org/integration/autoland/rev/a97f35aa5813
Part 17: Use GetWellKnownAtomInfo in ParserAtomsTable methods. r=nbp
https://hg.mozilla.org/integration/autoland/rev/6550f2638e10
Part 18: Remove WellKnownParserAtoms_ROM. r=nbp
https://hg.mozilla.org/integration/autoland/rev/11be0b92d7fa
Part 19: Move js_*_str to WellKnownAtom.h. r=nbp
https://hg.mozilla.org/integration/autoland/rev/8b5f8b69af1f
Part 20: Use pre-calculated hash in JSAtom common name initialization. r=nbp
https://hg.mozilla.org/integration/autoland/rev/b23da4ca0327
Part 21: Pre-calculate hash for symbol-related common names. r=nbp
Blocks: 1692680
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: