Skip to content

[v5.0] Put binary AST buffers into cache#6257

Merged
lukastaegert merged 32 commits intorollup-5from
binary-cache
Feb 20, 2026
Merged

[v5.0] Put binary AST buffers into cache#6257
lukastaegert merged 32 commits intorollup-5from
binary-cache

Conversation

@lukastaegert
Copy link
Copy Markdown
Member

@lukastaegert lukastaegert commented Feb 1, 2026

This PR contains:

  • bugfix
  • feature
  • refactor
  • documentation
  • other

Are tests included?

  • yes (bugfixes and features will not be merged without tests)
  • no

Breaking Changes?

  • yes (breaking changes will not be merged unless absolutely necessary)
  • no

List any relevant issue numbers:

Description

This finally removes the need to generate full ESTree ASTs at all in many situations and directly stores the binary buffers in the cache.
All generated ASTs except the ones returned by this.parse and the parseAst(Async) helpers will now be generated lazily, which means that all non-primitive properties of AST nodes are getters that are replaced with the actual properties on first access. This should severely reduce processing time if only some of the nodes are needed.
This will likely have quite some performance impact, especially when a standard ESTree-Walker is used. There might be a follow-up PR to provide an efficient interface to walk an AST without materializing nodes that are not needed.

Additionally, it exposes new helpers for manually converting an AST to binary and back.

Exports from rollup/parseAst

  • parseAst / parseAstAsync — return eager (fully materialized) ASTs
  • parseLazyAst / parseLazyAstAsync — new helpers returning lazy ASTs (same signatures as parseAst/parseAstAsync)
  • deserializeAst — new helper that deserializes a binary buffer to an eager AST (symmetric counterpart to deserializeLazyAst)
  • deserializeLazyAst — new helper that deserializes a binary buffer to a lazy AST
  • serializeAst — create binary buffer from a JSON AST

The lazy and non-lazy deserializers have interchangeable signatures.

BREAKING CHANGES

  • The cache is no longer purely JSON but instead JSON with Buffers/typed arrays in some fields. If people want to store this, it should still be possible to do via a JSON.stringify implementation with a custom serializer and storing the buffers in separate files.

@vercel
Copy link
Copy Markdown

vercel bot commented Feb 1, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
rollup Ready Ready Preview, Comment Feb 20, 2026 0:22am

Request Review

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 1, 2026

Thank you for your contribution! ❤️

You can try out this pull request locally by installing Rollup via

npm install rollup/rollup#binary-cache

Notice: Ensure you have installed the latest nightly Rust toolchain. If you haven't installed it yet, please see https://www.rust-lang.org/tools/install to learn how to download Rustup and install Rust.

or load it into the REPL:
https://rollup-olkptgmcg-rollup-js.vercel.app/repl/?pr=6257

@github-actions
Copy link
Copy Markdown

github-actions bot commented Feb 1, 2026

Performance report

  • BUILD: 6875ms, 785 MB (-5%)
    • initialize: 0ms, 24 MB
    • generate module graph: 2480ms (-85ms, -3.3%), 593 MB (-6%)
      • generate ast: 1330ms (-37ms, -2.7%), 605 MB (-3%)
    • sort and bind modules: 398ms, 651 MB (-6%)
    • mark included statements: 3914ms, 785 MB (-5%)
      • treeshaking pass 1: 2248ms, 789 MB (-4%)
      • treeshaking pass 2: 457ms, 792 MB (-6%)
      • treeshaking pass 3: 391ms, 783 MB (-6%)
      • treeshaking pass 4: 378ms, 800 MB (-5%)
      • treeshaking pass 5: 375ms, 785 MB (-5%)
  • GENERATE: 684ms, 878 MB (-4%)
    • initialize render: 0ms, 785 MB (-5%)
    • generate chunks: 39ms, 792 MB (-6%)
      • optimize chunks: 0ms, 784 MB (-7%)
    • render chunks: 628ms, 851 MB (-4%)
    • transform chunks: 17ms, 877 MB (-4%)
    • generate bundle: 0ms, 877 MB (-4%)

@codecov
Copy link
Copy Markdown

codecov bot commented Feb 1, 2026

Codecov Report

❌ Patch coverage is 96.21749% with 64 lines in your changes missing coverage. Please review.
✅ Project coverage is 98.37%. Comparing base (05992df) to head (ce48fae).
⚠️ Report is 1 commits behind head on rollup-5.

Files with missing lines Patch % Lines
src/utils/astToBuffer.ts 96.37% 30 Missing and 1 partial ⚠️
src/utils/bufferToLazyAst.ts 96.66% 22 Missing and 3 partials ⚠️
src/utils/getAstBuffer.ts 93.22% 4 Missing ⚠️
src/utils/parseAst.ts 50.00% 4 Missing ⚠️
Additional details and impacted files
@@             Coverage Diff              @@
##           rollup-5    #6257      +/-   ##
============================================
- Coverage     98.79%   98.37%   -0.43%     
============================================
  Files           272      273       +1     
  Lines         10702    12288    +1586     
  Branches       2846     2926      +80     
============================================
+ Hits          10573    12088    +1515     
- Misses           88      150      +62     
- Partials         41       50       +9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR introduces binary AST buffer caching and lazy AST generation to improve performance. Instead of storing full ESTree ASTs in the cache, Rollup now stores binary buffers and generates AST nodes lazily using getters that replace themselves on first access. This reduces memory usage and processing time when only some AST nodes are needed.

Changes:

  • Replaced full AST caching with binary buffer caching
  • Implemented lazy AST generation with self-replacing getters
  • Added AST serialization/deserialization helpers
  • Updated documentation to discourage returning ASTs from hooks

Reviewed changes

Copilot reviewed 150 out of 157 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
test/testHelpers.js Added test for AST serialization/deserialization roundtrip
test/function/samples/serialize-ast/* New test cases for AST serialization error handling
test/function/samples/plugin-error-should-transform/_config.js Updated to use astBuffer instead of ast in cache
test/function/samples/extend-more-hooks-to-include-import-attributes/_config.js Updated to use astBuffer instead of ast in cache
test/function/samples/enforce-plugin-order/_config.js Updated to use astBuffer instead of ast in cache
test/form/samples/custom-ast/* Removed test for custom AST support
test/cli/samples/unfulfilled-hook-actions/rollup.config.js Updated to use astBuffer instead of ast in cache
src/utils/transform.ts Modified to serialize AST to buffer format
src/utils/serialize-ast-strings.ts Generated file mapping strings to indices for serialization
src/utils/parseAstType.d.ts Added type definitions for new serialization functions
src/utils/parseAst.ts Updated to use lazy deserialization
src/utils/logs.ts Added error logging for AST serialization failures
src/utils/getAstBuffer.ts Added buffer creation and string encoding functions
src/utils/convert-ast-strings.ts Removed + and - operators from constant list
src/utils/astToBuffer.ts Generated file implementing AST to binary serialization
src/rollup/types.d.ts Updated types to use astBuffer and renamed interfaces
src/ast/* Removed generic type parameters from NodeBase classes
src/ModuleLoader.ts Updated to deserialize AST buffers when needed
src/Module.ts Changed to use binary buffers and lazy AST generation
src/Graph.ts Removed AST LRU cache, updated cache type
scripts/* Updated code generation scripts for serialization
docs/plugin-development/index.md Added documentation about lazy ASTs and serialization
docs/javascript-api/index.md Added documentation for AST serialization helpers
Comments suppressed due to low confidence (1)

test/function/samples/serialize-ast/undefined-for-optional/_config.js:1

  • The test expects exports.x to be an empty array [], but the AST defines it as { type: 'Literal', value: 42, raw: '42' }. The assertion will fail because the code says export const x = []; but the AST specifies the init value as the literal 42 instead of an empty array.

Comment thread scripts/helpers.js
lukastaegert and others added 4 commits February 20, 2026 13:19
* Convert scripts to TypeScript

* Auto-generate types

* Remove estree dependency

* Use ! instead of declare for more concise syntax

* Replace explicit enums with generated enums

* Use Super instead of SuperElement

to better align with type names

* Remove small and little-used interfaces

* Replace LeftHandSideExpression with Expression

This is what the proposed EStree update suggests

* Get rid of StatementBase in favor of NodeBase

* Also generate and use union types for builtins

* Generate parent types

* Improve types

* Remove many node identifiers
* Convert scripts to TypeScript

* Auto-generate types

* Remove estree dependency

* Use ! instead of declare for more concise syntax

* Replace explicit enums with generated enums

* Use Super instead of SuperElement

to better align with type names

* Remove small and little-used interfaces

* Replace LeftHandSideExpression with Expression

This is what the proposed EStree update suggests

* Get rid of StatementBase in favor of NodeBase

* Also generate and use union types for builtins

* Generate parent types

* Improve types

* Remove many node identifiers
@lukastaegert
Copy link
Copy Markdown
Member Author

I will improve coverage in #6271 further

@lukastaegert lukastaegert merged commit 112057f into rollup-5 Feb 20, 2026
46 of 48 checks passed
@lukastaegert lukastaegert deleted the binary-cache branch February 20, 2026 14:00
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