Skip to content

perf: Remove CLI code generation heuristics and improve performance - #5825

Merged
Crazelu merged 22 commits into
serverpod:mainfrom
Crazelu:fix/future-call-generation-on-serverpod-start
Oct 12, 2026
Merged

Crazelu merged 22 commits into
serverpod:mainfrom
Crazelu:fix/future-call-generation-on-serverpod-start

Conversation

@Crazelu

@Crazelu Crazelu commented Oct 5, 2026 •

Copy link
Copy Markdown
Collaborator

The CLI relied on string pattern matching to avoid regeneration runs when nothing of note has changed. That was brittle especially with inheritance support for endpoints and future calls. It also meant that changes to future calls that introduce parameters (future call models) were not correctly tracked on serverpod start.

This PR removes those hacks and relies on the analyzers to build the GenerationRequirements for partial or full generation runs.

The analysis and generation paths now use caching where necessary to remove expensive lookups that previously ran on every change including those that do not need generation (some were quadratic).

The analyzers now use file content fingerprinting to track changed files and decide what sets of paths to refresh analysis context with. Stamping has also improved with batches of multiple stamp actions running at once.

The performance gains are more obvious for generation steps. First time analyzer runs are much slower with the heuristics removed but subsequent runs (in --watch mode) are faster than the baseline.

Performance Benchmark Result

Baseline: 29f193bff231d786c4e3d94bb91893fe3176894e. Candidate: 360c5dfc0f52dbd4a217a93246703713e0787cfa plus working-tree edits.
Generated: 2026-10-08T15:28:13.493910Z. Host: macos Version 26.5.2 (Build 25F84), 8 processors.
Duration: 17 minutes.
Dart: 3.13.0 (stable) (Wed Aug 5 00:28:05 2026 -0700) on "macos_arm64".

Continuous generation (serverpod generate --watch)

Operation Metric Baseline median ms Candidate median ms Baseline / candidate Samples
First run on a clean project Analysis 7000 6900 1.01x 4 / 4
First run on a clean project Generation 400 300 1.33x 4 / 4
Add 1000 plain Dart files to a clean project Analysis 2000 1800 1.11x 1 / 1
Add 1000 future calls to a clean project Analysis 2600 2400 1.08x 1 / 1
Add 1000 future calls to a clean project Generation 6300 4100 1.54x 1 / 1
Add 1000 endpoints to a clean project Analysis 2500 2300 1.09x 1 / 1
Add 1000 endpoints to a clean project Generation 4300 4000 1.07x 1 / 1
Add 1000 YAML models to a clean project Analysis 400 200 2x 1 / 1
Add 1000 YAML models to a clean project Generation 26300 6100 4.31x 1 / 1
First run on the up-to-date large project Analysis 16300 14200 1.15x 1 / 1
Edit a future call without parameters in the large project Analysis 1000 900 1.11x 1 / 1
Edit a future call without parameters in the large project Generation 57900 5500 10.53x 1 / 1
Edit a future call with parameters in the large project Analysis 1600 900 1.78x 1 / 1
Edit a future call with parameters in the large project Generation 54500 4900 11.12x 1 / 1
Edit an endpoint in the large project Analysis 2700 900 3x 1 / 1
Edit an endpoint in the large project Generation 56000 5200 10.77x 1 / 1
Edit a YAML model in the large project Analysis 1500 800 1.88x 1 / 1
Edit a YAML model in the large project Generation 56200 10300 5.46x 1 / 1
Edit a plain Dart file in the large project Analysis 2600 2800 0.93x 1 / 1
Save an unchanged plain Dart file after a real change in the large project Analysis 900 900 1x 1 / 1
Save an unchanged plain Dart file again in the large project Analysis 900 1 900x 1 / 1

One-shot generation (serverpod generate)

Operation Metric Baseline median ms Candidate median ms Baseline / candidate Samples
First run on a clean project Analysis and generation 7300 7100 1.03x 4 / 4
Add 1000 plain Dart files to a clean project Analysis and generation 9900 8800 1.12x 1 / 1
Add 1000 future calls to a clean project Analysis and generation 14500 11200 1.29x 1 / 1
Add 1000 endpoints to a clean project Analysis and generation 12800 10800 1.19x 1 / 1
Add 1000 YAML models to a clean project Analysis and generation 33900 12500 2.71x 1 / 1
Generate the large project from scratch Analysis and generation 71300 23600 3.02x 1 / 1
Regenerate the large project after an edit Analysis and generation 75300 21400 3.52x 1 / 1

Closes #5760

Pre-launch Checklist

  • I read the Contribute page and followed the process outlined there for submitting PRs.
  • This update contains only one single feature or bug fix and nothing else. (If you are submitting multiple fixes, please make multiple PRs.)
  • I read and followed the Dart Style Guide and formatted the code with dart format.
  • I listed at least one issue that this PR fixes in the description above.
  • I updated/added relevant documentation (doc comments with ///), and made sure that the documentation follows the same style as other Serverpod documentation. I checked spelling and grammar.
  • I added new tests to check the change I am making.
  • All existing and new tests are passing.
  • Any breaking changes are documented below.

If you need help, consider asking for advice on the discussion board.

Breaking changes

@Crazelu Crazelu changed the title fix: Remove generation heuristics in CLI fix: Remove code generation heuristics in CLI Oct 5, 2026
@Crazelu
Crazelu marked this pull request as ready for review October 5, 2026 23:23
@Crazelu
Crazelu requested a review from a team October 5, 2026 23:24

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Crazelu For reference, have you measured the impact of removing the heuristics on a fresh analyze? This is relevant data to include in the PR description for the future.

@Crazelu
Crazelu marked this pull request as draft October 6, 2026 16:43
@Crazelu
Crazelu force-pushed the fix/future-call-generation-on-serverpod-start branch from f987170 to e5cf491 Compare October 7, 2026 23:30
@Crazelu Crazelu changed the title fix: Remove code generation heuristics in CLI perf: Remove CLI code generation heuristics and improve performance Oct 8, 2026
@Crazelu
Crazelu marked this pull request as ready for review October 8, 2026 00:09
@Crazelu

Crazelu commented Oct 8, 2026

Copy link
Copy Markdown
Collaborator Author

@marcelomendoncasoares the benchmark result is up now

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made a first review focused mainly on the cache/invalidation, since it is where we can hit most issues (and degrade UX the most).

@marcelomendoncasoares marcelomendoncasoares left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! 🚀

@Crazelu
Crazelu merged commit d65d22e into serverpod:main Oct 12, 2026
958 of 960 checks passed
@github-actions github-actions Bot locked and limited conversation to collaborators Oct 12, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

serverpod start: adding a future call with parameters generates code that imports a model file that is never written

2 participants