Skip to content

Optimize unchanged FiberRefs updates#6453

Draft
coyaSONG wants to merge 1 commit into
Effect-TS:v3from
coyaSONG:agent/avoid-fiberref-noop-copy
Draft

Optimize unchanged FiberRefs updates#6453
coyaSONG wants to merge 1 commit into
Effect-TS:v3from
coyaSONG:agent/avoid-fiberref-noop-copy

Conversation

@coyaSONG

@coyaSONG coyaSONG commented Jul 17, 2026

Copy link
Copy Markdown
Contributor

Type

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

FiberRefs.updateAs cloned the complete locals map before unsafeUpdateAs could discover that the current fiber already held an equal value. Repeated unchanged FiberRef updates therefore remained O(R) in the number of unrelated refs.

This change computes the replacement stack first and returns the original FiberRefs when the same fiber's value is unchanged. Updates from a different fiber still append a history entry, and changed values still copy the map to preserve immutable snapshots.

A local 7-sample median microbenchmark with 500 populated refs and 20,000 unchanged updates measured the map-cloning baseline at 476.9 ms and the optimized path at 0.69 ms (about 691x faster).

Implementation and validation were assisted by OpenAI Codex. No independent human review is claimed.

Validation:

  • corepack pnpm lint-fix
  • corepack pnpm vitest packages/effect/test/FiberRefs.test.ts packages/effect/test/FiberRef.test.ts --run (40 tests)
  • corepack pnpm check
  • corepack pnpm build
  • corepack pnpm docgen
  • git diff --check

Related

@github-project-automation github-project-automation Bot moved this to Discussion Ongoing in PR Backlog Jul 17, 2026
@changeset-bot

changeset-bot Bot commented Jul 17, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: bd05883

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
effect Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@IMax153 IMax153 added the 3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3. label Jul 17, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.0 Used for issues, pull requests, etc. that are relevant for the `v3` branch targeting Effect v3.

Projects

Status: Discussion Ongoing

Development

Successfully merging this pull request may close these issues.

2 participants