Open Bug 1544117 Opened 1 year ago Updated 20 days ago

[meta] Parse JS without allocating on the GC


(Core :: JavaScript Engine, enhancement, P2)





(Reporter: tcampbell, Unassigned)


(Depends on 8 open bugs, Blocks 7 open bugs)


(Keywords: meta)

Off-thread parsing currently results in complexities around GC interactions.

Currently we do the following steps for off-thread parsing:

  • Create a new gc::Zone, Compartment, and Realm/Global
  • Use AutoKeepAutos to prevent main-thread from starting any GC in AtomsZone
  • Do the parse
    • Create GC things in our Realm as we go
      • Inner-functions
      • RegExp
      • Object literals (including their Shape)
      • Scopes
      • Atomize property-names and string-literals as we go,
        taking global locks in the AtomZone as needed.
  • Perform 'mergeRealms' step to munge the temporary Zone into the target
    zone, performing minor updates on gc-things as we transfer ownership.

There is also a lot of hard to follow code around these GC-things as the are incrementally constructed across various parts of parser and frequently used in partially initialized states.

We are starting to see more examples of real-world perf impact by the off-thread parse getting conflicting with main-thread such as Bug 1543776 and atom lock contention that sometimes shows up.

In this bug I'd like for us to look at what the minimal requirements would be to fix in our existing parser. This would involving atomizing private to the parser (in the off-thread case), and replacing the ObjectBox design.

Matthew has been working away on the FunctionBox aspect of this which is probably the most challenging. Patches are being reviewed and landed to decouple Parser from JSFunction/LazyScript. The following topics still need more planning and work:

  • Decouple BytecodeEmitter from JSFunction/JSScript
  • Decouple Parser from JSAtom
  • Decouple ObjectBox, etc
  • Create the GC-things directly in target realm (instead of using mergeRealms)
Depends on: 1567579, 1558604, 1569315
Keywords: meta
Summary: Investigate changing JS Parser to not create GC things as we go → [meta] Parse JS without allocating on the GC
Type: task → enhancement
Blocks: 1586771
Blocks: 1589767
No longer blocks: 1589767
Depends on: 1589767
Blocks: stencil
Blocks: 1611437
Depends on: 1619002
Depends on: 1620776
You need to log in before you can comment on or make changes to this bug.