Skip to content

continuationMarksStack formats a stack at module load even when Error.stackTraceLimit is 0 #8936

Closed

Description

@akirasosa

Follow-up to #8038 / #8114.

continuationMarksStack in packages/effect/src/internal/effect.ts (added in #8386) formats a stack at module load:

const continuationMarksStack = (() => {
  const marker = "~effect/Effect/stackProbe"
  const probe = { [marker]: function stackProbe() { return new Error().stack } }
  ...
})()

It runs even when Error.stackTraceLimit is 0. The other load-time probe in Utils.ts is guarded (getStackTraceLimit() !== 0 && ...), and #8114 added the same guard to the Effect.fn / span / layer capture sites, but this one was missed. Still the case in 4.0.2.

Why it matters on Cloudflare Workers: with upload_source_maps enabled, the first time an isolate formats a stack it loads the source map. For us that is a ~36 MB map, and doing it inside module evaluation costs about 150 ms of startup CPU. Our chat worker went from 176 ms (before adopting Effect 4) to 339–430 ms, measured with wrangler versions upload. With Error.stackTraceLimit = 0 set around module load plus this one-line change, it is back to 177 ms. Setting the limit alone is not enough because the probe formats the stack regardless (376 ms). wrangler check startup doesn't show it because the local runtime doesn't load the map.

Suggested change, mirroring Utils:

const continuationMarksStack = (() => {
  if (getStackTraceLimit() === 0) return false
  ...
})()

We're carrying this as a bun patch for now and would like to drop it. Happy to provide more numbers if useful.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions