Skip to content

Optimize fiber message queue draining#6437

Draft
coyaSONG wants to merge 1 commit into
Effect-TS:v3from
coyaSONG:agent/fix-fiber-message-queue
Draft

Optimize fiber message queue draining#6437
coyaSONG wants to merge 1 commit into
Effect-TS:v3from
coyaSONG:agent/fix-fiber-message-queue

Conversation

@coyaSONG

Copy link
Copy Markdown
Contributor

Type

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

Description

FiberRuntime stored pending fiber messages in an array and removed the first item with splice(0, 1). Each dequeue shifted the remaining items, making a burst of N queued messages quadratic to drain.

This replaces that array with Effect's existing unbounded MutableQueue and uses offer, poll, and isEmpty throughout the runtime. FIFO behavior and the existing scheduling logic are preserved, while enqueue and dequeue are constant-time. There is no public API change. A patch changeset is included.

A local median benchmark for draining 60,000 no-op stateful messages changed from 274.125 ms on the untouched base to 3.563 ms with this patch (about 77x faster).

Validation:

  • corepack pnpm lint-fix
  • corepack pnpm check
  • corepack pnpm build
  • corepack pnpm docgen
  • pnpm test run packages/effect/test/Fiber.test.ts packages/effect/test/Runtime.test.ts — 24 passed
  • pnpm test run packages/effect/test — 6,210 passed, 7 skipped, 3 todo; one unrelated BigDecimal/clampBigDecimal assertion failed locally under both Node 25 and Node 24. The test, helper, and BigDecimal source are unchanged by this PR, and the current upstream base Check run is green.

Development note: the implementation and PR text were prepared with AI assistance and validated with the repository checks above; no human review is claimed.

Related

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

changeset-bot Bot commented Jul 16, 2026

Copy link
Copy Markdown

🦋 Changeset detected

Latest commit: a8a4717

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 16, 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