Skip to content

⚡️Use prototyped class for ScopeInternal - #1184

Open
cowboyd wants to merge 1 commit into
v4from
classify-scope-internal
Open

cowboyd wants to merge 1 commit into
v4from
classify-scope-internal

Conversation

@cowboyd

@cowboyd cowboyd commented Jun 10, 2026

Copy link
Copy Markdown
Member

Motivation

The scope implementation was creating a unique prototype for every single scope instance which caused depotimization of every single scope method.

Approach

This extracts all the core methods into a single prototype based class that shares a single implementation among all instances, which allows V8 (and presumably other runtimes) to inline the implementation.

@pkg-pr-new

pkg-pr-new Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

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

commit: 40a5cb3

@codspeed

codspeed Bot commented Jun 10, 2026 •

Copy link
Copy Markdown

Merging this PR will improve performance by 15.25%

1 warning

⚠️ 2 benchmarks with a significant change ran on different hardware

Their base and head results were measured on machines with a different CPU, core count or memory, so the changes might not come from the code. Run base and head on the same runner type.

Learn more about Macro Runners

See affected benchmarks

⚡ 2 improved benchmarks
✅ 4 untouched benchmarks

Performance Changes

Mode Benchmark BASE HEAD Efficiency
⚡ Memory effection-inline.recursion 5.9 KB 4.9 KB +20.25%
⚡ CPU Simulation effection-inline.recursion 506.6 µs 458.7 µs +10.45%

Tip

Curious why performance improved? Comment @codspeedbot explain why performance improved on this PR, or directly use the CodSpeed MCP with your agent.


Comparing classify-scope-internal (40a5cb3) with v4 (8504c03)

Open in CodSpeed

@cowboyd

cowboyd commented Jun 10, 2026

Copy link
Copy Markdown
Member Author

Pre-merge check: verify Symbol-keyed augmentations still work

The wrapper change moves scope from Object.create({...closures...}) to Object.create(Scope, {own-bound-methods}). Symbol.toStringTag lives on the shared Scope prototype (good), but two Symbol-keyed properties are added after construction by createScope:

  • Symbol.iterator — lib/scope.ts:75-78, used for tuple destructuring let [scope, dispose] = createScope()
  • Symbol.asyncDispose — lib/scope.ts:80-83, used by await using scope = createScope()

Both rely on Object.defineProperty(scope, ...) succeeding on the returned scope object. Should still work since the wrapper is a plain object, but worth running:

  1. A test that destructures createScope() as a tuple
  2. A test that uses await using semantics

If both pass on this branch, this comment can be resolved.

@cowboyd
cowboyd marked this pull request as ready for review July 7, 2026 12:57
@scottkgaran

Copy link
Copy Markdown

@cowboyd anything blocking to get this in? 😄

@cowboyd

cowboyd commented Dec 4, 2026

Copy link
Copy Markdown
Member Author

@cowboyd anything blocking to get this in? 😄

We definitely will land it in both branches

The scope implementation was creating a unique prototype for every
single scope instance which caused depotimization of every single
scope method.

This extracts all the core methods into a single prototype based
class that shares a single implementation among all instances, which
allows V8 (and presumably other runtimes) to inline the
implementation.
@github-actions

github-actions Bot commented Dec 5, 2026 •

Copy link
Copy Markdown
Contributor

🚀 Deploy Preview Ready!

Effection is a structured concurrency and effects framework for JavaScript.
Effection is a structured concurrency and effects framework for JavaScript.

This branch was successfully deployed

1 active deployment
Preview — 40a5cb33 Deployed Dec 5, 2026 by cowboyd via deploy-preview #1466
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.

2 participants