Closed Bug 1544117 Opened 3 years ago Closed 1 year ago

[meta] Parse JS without allocating on the GC

Categories

(Core :: JavaScript Engine, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED

People

(Reporter: tcampbell, Unassigned)

References

(Blocks 1 open bug)

Details

(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: 1589767
No longer blocks: 1589767
Depends on: 1589767
Blocks: stencil
Blocks: 1611437
Depends on: 1619002
Depends on: 1620776
Depends on: 1627369
Depends on: 1631407
Depends on: 1635976
Depends on: 1636247
Depends on: 1636794
Depends on: 1636800
Depends on: 1637299
Depends on: 1639612
Depends on: 1623956
Depends on: 1641202
Depends on: 1641419
Depends on: 1641442
Depends on: 1642716
No longer depends on: 1642716
Depends on: 1649968
Depends on: 1651880
Depends on: 1652056
Depends on: 1652472
Depends on: 1652728
Depends on: 1655052
Depends on: 1655768
Depends on: 1659595
No longer depends on: 1649968
No longer depends on: 1655052
No longer depends on: 1655768
No longer blocks: 1543776
No longer blocks: 1543806
No longer blocks: 1611437
No longer blocks: 1587847

The machinery is in place within the Parser so I think we can close this bug. Other bugs will track making use of these changes.

Status: NEW → RESOLVED
Closed: 1 year ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.