Skip to content

Fix out-of-memory error during wayfinder:generate on a cold cache - #287

Merged
joetannenbaum merged 6 commits into
laravel:nextfrom
alaminfirdows:fix/generate-memory-limit
Sep 9, 2026
Merged

Fix out-of-memory error during wayfinder:generate on a cold cache#287
joetannenbaum merged 6 commits into
laravel:nextfrom
alaminfirdows:fix/generate-memory-limit

Conversation

@alaminfirdows

Copy link
Copy Markdown

Description

wayfinder:generate fatal-errors with Allowed memory size of 134217728 bytes exhausted when run against a cold cache (empty storage/wayfinder-cache) under PHP's default 128M memory limit (see #167).

The static analysis pass (via laravel/surveyor) retains every analyzed scope in memory for the duration of the walk, and that working set exceeds 128M for non-trivial applications on a first run. The command then dies mid-generation instead of producing output.

This change lifts the memory limit for the wayfinder:generate command when it has been capped. It is a build-time, short-lived CLI process (the same approach used by Composer and other code-generation tools), so removing the cap is safe and lets generation complete reliably regardless of application size.

Closes #167

Benefit to end users

Users can run php artisan wayfinder:generate (directly, or via the Vite plugin during npm run build) under the default PHP memory configuration without hitting a fatal out-of-memory error on a cold cache.

Non-breaking changes

  • The limit is only ever raised, never lowered. If the environment already sets memory_limit = -1, the command is a no-op.
  • ini_set is suppressed, so environments that forbid changing the limit at runtime fall back to the previous behavior rather than erroring.
  • No generated output or public API changes.

Tests

Added test_generate_completes_under_default_memory_limit, which runs wayfinder:generate in a subprocess constrained to memory_limit=128M and asserts it succeeds. This fails before the change (fatal OOM) and passes after. The existing GenerateCommandTest suite and the Vitest globalSetup build (which runs wayfinder:generate at the default limit) also complete under 128M with this change.

The static analysis pass keeps every analyzed scope in memory and can
exceed PHP's default 128M limit on a cold cache, causing a fatal
out-of-memory error mid-generation.

Since this is a build-time command, lift the memory limit when it has
been capped instead of failing mid-generation.
@github-actions

github-actions Bot commented Jul 5, 2026

Copy link
Copy Markdown

Thanks for submitting a PR!

Note that draft PRs are not reviewed. If you would like a review, please mark your pull request as ready for review in the GitHub user interface.

Pull requests that are abandoned in draft may be closed due to inactivity.

@alaminfirdows
alaminfirdows marked this pull request as ready for review July 6, 2026 05:22
@joetannenbaum

Copy link
Copy Markdown
Collaborator

Thank you!

@joetannenbaum
joetannenbaum merged commit b44a120 into laravel:next Sep 9, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants