WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content

Very high memory consumption during "Discovering workflow directives" phase in large Next.js applications #523

@bholbein

Description

@bholbein

When using the Workflow SDK (withWorkflow()) in a large Next.js 15 application, the "Discovering workflow directives" phase consumes excessive memory, causing builds to fail with OOM errors on standard
build machines (16 GB RAM).

Environment

  • Next.js: 15.5.6
  • Workflow SDK: 4.0.1-beta.24 (also tested with 4.0.1-beta.21)
  • Node.js: 20
  • Build Environment: Vercel (16 GB RAM machines)
  • Platform: macOS (local), Linux (Vercel)

Problem

The SDK scans the entire app/ directory (and other conventional directories like pages/, src/app/, src/pages/) to discover files containing 'use workflow' and 'use step' directives. In our application with
914 TypeScript/TSX files in the app/ directory but only ~11 files actually using workflow directives, this causes:

  1. 16x memory increase compared to builds without the workflow plugin
  2. Build failures due to OOM on 16 GB machines
  3. "Discovering workflow directives" phase taking ~30 seconds

Memory Metrics

Scenario RSS Memory Heap Used
Build without VERCEL=1 (no workflow plugin) 267 MB 90 MB
Build with VERCEL=1 (workflow plugin active) 4,465 MB 2,716 MB
Vercel preview build ~15.7 GB (98% of 16 GB) -

Root Cause Analysis

The issue might stems from @workflow/builders in base-builder.js:

  async discoverEntries(inputs, outdir) {
    await esbuild.build({
      entryPoints: inputs,  // ALL files from app/, pages/, etc.
      bundle: true,         // Full bundle for discovery
      // ...
    });
  }

And in @workflow/next:

dirs: ['pages', 'app', 'src/pages', 'src/app'], // HARDCODED, not configurable

The SDK uses esbuild to bundle every file in these directories as entry points just to discover which ones contain workflow directives. For large applications, this causes significant memory consumption.

Metadata

Metadata

Assignees

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