Hypothesis
In walkSync (lazy-result.js:525-574), node.toProxy() may be called up to 4 times for the same node: enter listeners (line 543), keyed enter (550), exit listeners (563), keyed exit (570). While toProxy() caches the Proxy on the node, each call still involves: function call overhead, WeakMap lookup (proxyCache), and conditional check.
The code already partially optimizes this with the local proxy variable, but it still calls toProxy() at each phase if the previous phase had no visitors. Cache the proxy unconditionally at the start of walkSync for any node that has ANY listeners:
// Pre-check: does this node type have any listeners at all?
let hasAnyVisitor = listeners[type] || listeners[type + 'Exit']
if (key) hasAnyVisitor = hasAnyVisitor || listeners[type + '-' + key] || listeners[type + 'Exit-' + key]
let proxy = hasAnyVisitor ? node.toProxy() : null
This reduces toProxy() calls from up to 4 per node to exactly 0 or 1.
Editable surface
- lib/lazy-result.js — restructure walkSync to call toProxy at most once per node
What's different from prior work
Expected impact
METRIC_B improvement of 1-3ms. Combined with other optimizations in the same thesis, could contribute to crossing tolerance.
Hypothesis
In walkSync (lazy-result.js:525-574), node.toProxy() may be called up to 4 times for the same node: enter listeners (line 543), keyed enter (550), exit listeners (563), keyed exit (570). While toProxy() caches the Proxy on the node, each call still involves: function call overhead, WeakMap lookup (proxyCache), and conditional check.
The code already partially optimizes this with the local proxy variable, but it still calls toProxy() at each phase if the previous phase had no visitors. Cache the proxy unconditionally at the start of walkSync for any node that has ANY listeners:
This reduces toProxy() calls from up to 4 per node to exactly 0 or 1.
Editable surface
What's different from prior work
Expected impact
METRIC_B improvement of 1-3ms. Combined with other optimizations in the same thesis, could contribute to crossing tolerance.