Skip to content

Add hooks to allow object slot-reordering optimization in NightMonkey. - #4

Open
cfallin wants to merge 3 commits into
wasi-ff147from
cfallin/external-slots
Open

cfallin wants to merge 3 commits into
wasi-ff147from
cfallin/external-slots

Conversation

@cfallin

@cfallin cfallin commented Oct 9, 2026

Copy link
Copy Markdown
Member

This PR adds hooks to allow reordering object slots in order to allow an AOT compiler tier (e.g. NightMonkey) to more effectively predict object slots, staying on the fastpath more often.

Also includes two other small changes needed for NightMonkey (exposing a few more details on invariant fuses and permitting compiled code to access the external-compiler context pointer).

An external compilation tier may wish to place slots in objects in
certain ways to improve commonality or predictability of these slots,
especially when they are derived from static analysis.

This PR adds the necessary hooks to:
- Permit creation of shapes that "permute" slots: assign slots in a
  different order than the walk up the shape tree. Places in the runtime
  that assume shape-walk order is the same as property order are
  modified.
- Specify the shape to use when a property is added, overriding the
  default lookup or lazy shape creation.

To support "permuted shapes", we add a new flag, `PermutedSlots`, and we
track the shape *span* (max slot + 1) separately from the index of the
bottommost shape. Both GC scans and new property additions in generic
(not-hooked) paths need this span to choose the next slot to use.

With NightMonkey's use of these hooks, all jit-tests (including tests
that iterate over properties in added order) continue to pass; the order
of shapes up the shape tree still represents the semantically-visible
order in which properties were added. It is just the order of assigned
slots that can differ.

All changes are ifdef'd under JS_EXTERNAL_COMPILER_HOOKS; without it
hasPermutedSlots() is false and the engine is unchanged.
An external tier might wish to specialize on a constant value for a
global. Previously, there was no way for the external compiler to
subscribe to / have access to a fuse associated with a global's value.
This PR adds the necessary hook.
@cfallin
cfallin requested a review from tschneidereit October 9, 2026 20:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant