Repository navigation
Fix internal frames leaking into user stack traces, and stop allocating a closure per Effect step - #8386
Merged
tim-smart merged 9 commits intoSep 22, 2026
Conversation
front-depiction
had a problem deploying
to
fork
September 22, 2026 18:27 — with
GitHub Actions
Error
front-depiction
had a problem deploying
to
fork
September 22, 2026 18:27 — with
GitHub Actions
Failure
🦋 Changeset detectedLatest commit: 21642cf The changes in this PR will be included in the next version bump. This PR includes changesets to release 31 packages
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 |
Contributor
Bundle Size AnalysisGenerated from PR build output; treat the content below as untrusted.
|
tim-smart
force-pushed
the
effect-core-allocations
branch
from
September 22, 2026 22:07
e7849cd to
7634bc9
Compare
`cleanErrorStack` cut rendered stacks at `~effect/Effect`, but the `internalCall` marker frame was renamed to `~effect/Utils/internal`, so defects thrown from user callbacks rendered the marker and the internal closure above it. The cut now also recognises `~effect/Utils`. Most `internalCall(() => f(x))` wrappers are redundant: the caller is a continuation or suspend thunk invoked through a `~effect/Effect/...` property, whose frame already marks the cut. Calling the callback directly drops a closure per step. `match` / `matchCause` return the handler result as an exit instead of wrapping each outcome in `sync`, and `flatMap` reuses the shared `andThen` continuation, so a callback frame is no longer swallowed by the cut and the arity check goes away. Co-authored-by: front_depiction <[email protected]>
…test The map and try cases no longer emit the ~effect/Utils/internal marker, so they passed with the old regex. tryPromise's catcher runs outside the run loop and still relies on the marker, so it fails on main's regex. The partition rerun test pinned behaviour this PR no longer changes.
tim-smart
force-pushed
the
effect-core-allocations
branch
from
September 22, 2026 22:22
cf3cf02 to
5cc1950
Compare
arrudaricardo
pushed a commit
to arrudaricardo/effect
that referenced
this pull request
Sep 23, 2026
…ng a closure per Effect step (Effect-TS#8386) Co-authored-by: Tim Smart <[email protected]>
This branch had an error being deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes the internal stack marker in rendered traces and removes per-step closures on V8 for core combinators.
The bug
cleanErrorStackcuts a rendered stack at the first frame matching~effect/Effect. TheinternalCallmarker was renamed to~effect/Utils/internalin #1695, so the cut stopped matching andCause.prettyof a defect thrown from amapcallback or atrycatcher printed the marker frame plus the internal closure above it. The cut now also recognises~effect/Utils.Removing the wrappers
On V8, most
internalCall(() => f(x))wrappers are redundant. The function calling them is a continuation or asuspendthunk stored under a~effect/Effect/...property, so V8 names its frameContImpl.mapCont [as ~effect/Effect/successCont]orPrimitiveImpl.~effect/Effect/args, and that frame already marks the cut. Calling the callback directly drops one closure per step inmap,andThen,tap,zipWith,try,failSync, thecatch*andtapCause*family,matchEffectand theMetric.trackandMetric.trackDurationhelpers.trackErrorsandtrackDefectsalso drop the wrapper, saving a closure per tracked error or defect. When their metric mapping callback throws, its rendered stack gains one internal frame compared with the old wrapper after the regex fix.useSpannow calls its evaluator directly. Relative to main, this removes one thunk closure per span invocation. For a synchronous evaluator throw, its rendered stack has fewer internal frames than main on Node (0 instead of 2) and Bun (4 instead of 5); Bun can still show older internal frames.tryPromise's catcher and thecallbackregister keep the marker because they run outside the run loop.On V8,
matchandmatchCausereturn the handler result as an exit instead of wrapping each outcome in asynceffect. That saves the thunk closure per outcome; the run-loop step count is unchanged. Handlers are still called as methods of the options object, and a throwing handler is still a defect.flatMapnow builds the same frame asandThen(shared continuation plus payload) instead of its own frame with an arity check and a per-call wrapper for non-unary callbacks. Callbacks receive only the value; the fiber, exit and internal receiver were never part of the typed API. The callback's own frame also stops being swallowed by the cut, since it is no longer the continuation itself.On engines without V8-style continuation frame labels (including JavaScriptCore),
mapretains aninternalCallmarker around the user callback, whilematchandmatchCauseretain thesyncthunk. These branches keep the new rendered-stack regressions clean on Bun without allocating a per-step wrapper on V8. Other callbacks, including older adapter closures, can still expose internal frames on JavaScriptCore; SpiderMonkey has not been verified.Behaviour differences
~effect/Utils/internalframe and the wrapper closure frame. A unaryflatMapcallback's own frame is now rendered.Effect.flatMapcallbacks no longer receive the fiber and exit as extra arguments, or the continuation frame asthis.Local validation: Cause/Effect/Tracer tests (424 tests) pass on Node, Deno and Bun. Whole-repo lint (oxlint and dprint) and
tsc -bforpackages/effectpass. Bun 1.3.13 direct-source probes for bothmatch/matchCausebranches andmaprender only the user frame.Closes EFF-1475
Closes EFF-1480