Skip to content

perf: array-callback invocation costs ~368 instructions per call — 77% of the forEach gap, vs ~23% for #8103's element-shape fact #8180

Description

@proggeramlug

Summary

Triaging #8103 sized its prize and found the element-shape fact is only a ~23% ceiling. The other ~77% is per-callback invocation machinery — roughly 368 instructions per call. forEach is about 16x the equivalent for loop, and landing #8103 as written would leave it there.

This is filed separately because #8103 is scoped to a repsel fact and this is not; working #8103 first would deliver under a quarter of the available win.

The measurement

Reproduced #8103's own program (same t: 80000000000, same Ptr<Shape> verdicts: 0 selected / 1 denied), then isolated the components by replacing the callback body with s = s + 1:

component instructions share
field reads inside the callback 435.9 M ~23%
per-callback invocation ~1.47 G ~77%
total 1.91 G

Against a for loop over the same data: 92.1 M vs 1.32 G, a 14x gap — not the 10.1% #8103 reports. That issue's percentage was diluted by a ~15.7 G common term; its increment (1.59 G) does match the measured 1.23 G, so the absolute finding was sound and only the ratio was wrong.

~368 instructions per callback invocation is the number to attack.

Why this is the better target

Caveat on the split, stated honestly

The 23/77 partition was measured under an opt-level-1 runtime. Both sides of the split are runtime calls, so it is less biased than a generated-vs-runtime comparison would be, but the bias was not bounded. Worth re-establishing at release opt-level before committing significant work.

What to look at

The invocation path is js_closure_call* plus whatever the fused array helpers do per element — argument marshalling, NaN-boxing, and the handle/rooting traffic around each call. Two adjacent findings that may share the cost:

Refs #8103, #8179, #8175.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions