Skip to content

shared scope prototype#1197

Open
jbolda wants to merge 2 commits into
v4from
shared-scope-prototype
Open

shared scope prototype#1197
jbolda wants to merge 2 commits into
v4from
shared-scope-prototype

Conversation

@jbolda

@jbolda jbolda commented Jul 1, 2026

Copy link
Copy Markdown
Member

Motivation

Playing around with @e18e/deopt to see if we can squeeze out a bit more perf. With scope being hit so often, having a shared prototype avoids some deopt.

Approach

  • this seemed to be the biggest gain, and presume it will be a situation that continues to exist in the future
  • other items raised seemed to not make as much of a difference and/or felt like they could change in the future

Deoptimization report

deopt: dependent allocation site transition changed (high)

  • build/npm/esm/lib/api.js:53:24 dispatch

deopt: unexpected name in keyed access (high)

  • build/npm/esm/lib/api.js:55:65

deopt: wrong map (high)

The optimized code was specialized for objects of one shape here, but got an object with a different shape, so it had to deoptimize. Keep the objects reaching this line consistent (the same properties added in the same order) so V8 can rely on their shape.

  • build/npm/esm/lib/api.js:57:21 $scope.reduce.min

ic: megamorphic (high)

This access saw too many different object shapes, so its inline cache went megamorphic and V8 can no longer optimize it. Keep the objects reaching this line consistent (the same properties added in the same order) so the access can stay monomorphic.

  • build/npm/esm/lib/api.js:55:65
  • build/npm/esm/lib/api.js:67:28 createHandle
  • build/npm/esm/lib/api.js:68:25 createHandle
  • build/npm/esm/lib/api.js:68:63 handle.
  • build/npm/esm/lib/scope-internal.js:12:30 get
  • build/npm/esm/lib/scope-internal.js:97:35 reduce
  • build/npm/esm/lib/scope-internal.js:134:32 destroy
  • build/npm/esm/lib/delimiter.js:100:27 close
  • build/npm/esm/lib/delimiter.js:107:25 close
  • build/npm/esm/lib/api/scope.js:8:39 set
  • build/npm/esm/lib/box.js:4:26 box

code: optimization churn (medium)

V8 re-optimized this function repeatedly without settling on a single optimized version. This churn wastes compilation work and usually points to types or object shapes that keep changing between calls. Keep the values reaching this function consistent so V8 can optimize it once and keep that code.

  • build/npm/esm/lib/api.js:53:24 dispatch

ic: polymorphic (medium)

  • build/npm/esm/lib/delimiter.js:134:28
  • build/npm/esm/lib/task.js:41:25

@pkg-pr-new

pkg-pr-new Bot commented Jul 1, 2026

Copy link
Copy Markdown

Open in StackBlitz

npm i https://pkg.pr.new/effection@1197

commit: 000e3c4

@codspeed-hq

codspeed-hq Bot commented Jul 1, 2026

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 6 untouched benchmarks


Comparing shared-scope-prototype (000e3c4) with v4 (49fe66f)

Open in CodSpeed

@jbolda jbolda marked this pull request as ready for review July 1, 2026 18:12
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