Files
Peter Wielander fd621b1167 perf(core): ship build-time V8 code cache for workflow bundles
On a cold serverless instance the first replay parses the entire workflow
bundle before it can reach the first step. The in-process vm.Script cache
(#2471) only helps subsequent replays in the same process; the cold first
one still pays a full parse, which grows ~30ms/MB and dominates
time-to-first-step for large bundles.

Producer (builders/next): for bundles over a size threshold, compile the
bundle at build time and emit Script.createCachedData() as base64 in the
generated flow route, passed via workflowEntrypoint's cachedData option.
Skipped for small bundles (parse is ~1ms; the blob would just bloat the
artifact) and via WORKFLOW_DISABLE_BUNDLE_CODE_CACHE.

Consumer (core): getCachedWorkflowScript compiles with the cachedData so
V8 skips parsing on the first compile. The blob is filename-independent so
one build-time cache serves every per-workflow filename; V8 validates it
and falls back to a full parse on any version/source mismatch, so a stale
blob is never a correctness risk.

Measured fresh-process parse: 2MB 34->4.8ms, 8MB 147->21ms (~7x).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-06-18 14:28:01 -07:00
..
2026-06-17 17:20:44 -07:00
2026-06-17 17:20:44 -07:00

@workflow/builders

Shared builder infrastructure for Workflow SDK. This package provides the base builder class and utilities used by framework-specific integrations.

Overview

This package contains the core build logic for transforming workflow source files into deployable bundles. It is used by:

  • @workflow/cli - For standalone/basic builds
  • @workflow/next - For Next.js integration
  • @workflow/nitro - For Nitro/Nuxt integration

Key Components

  • BaseBuilder: Abstract base class providing common build logic
  • Build plugins: esbuild plugins for workflow transformations
  • SWC integration: Compiler plugin integration for workflow directives

Usage

This package is typically not used directly. Instead, use one of the framework-specific packages that extend BaseBuilder:

import { BaseBuilder } from '@workflow/builders';

class MyBuilder extends BaseBuilder {
  async build(): Promise<void> {
    // Implement builder-specific logic
  }
}

Architecture

The builder system uses:

  1. esbuild for bundling and tree-shaking
  2. SWC for transforming workflow directives ("use workflow", "use step")
  3. Enhanced resolve for TypeScript path mapping

License

MIT