Skip to content

refactor: emit the content data store as a JSON string - #17430

Merged
ocavue merged 8 commits into
mainfrom
ocavue/data-store-json-parse
Jul 31, 2026
Merged

ocavue merged 8 commits into
mainfrom
ocavue/data-store-json-parse

Conversation

@ocavue

@ocavue ocavue commented Jul 19, 2026 •

Copy link
Copy Markdown
Contributor

AI discourse: most works are done by Claude Fable 5

Changes

Why:

  • The object literal's AST grows with the store. In dev, Vite's SSR transform feeds the module through rolldown/oxc-parser, which serializes the whole AST into a single JSON string across the NAPI bridge; for multi-MB stores that string exceeds V8's maximum string length and collections silently come back empty (getCollection() silently returns empty in dev when the data store has many entries #17220). Fix getCollection() returning empty in dev mode for large content collections #17223 worked around this with a dev-only size threshold; emitting a string unconditionally removes the failure class structurally instead of by heuristic.
  • A string literal keeps the module's AST size constant, and JSON.parse is roughly 1.7x faster than parsing the equivalent object literal (https://v8.dev/blog/cost-of-javascript-2019#json), so server cold starts get slightly faster as stores grow.
  • Precedent: Vite's own JSON plugin defaults to json.stringify: 'auto', which emits JSON.parse("...") for any JSON module over 10kB for the same reasons, and the chunked store mode (feat: chunk data store #17296) already ships serialized strings in both dev and production.
  • dataToEsm() adds nothing here: the store's top level is a devalue-flattened array, so the generated module has a single default export and there are no named exports to tree-shake. Its output is essentially the on-disk JSON with unquoted keys.
  • Cost: the data store module in the (unminified) server bundle grows about 9% raw from string escaping, about 1% after gzip. Client bundles are unaffected; nothing client-reachable imports this module.

Testing

Green CI

Docs

No docs needed: this changes the internal representation of a virtual module with no user-facing behavior change. No changeset file is added.

@changeset-bot

changeset-bot Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

⚠️ No Changeset found

Latest commit: 8fdcc52

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets

When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

@github-actions github-actions Bot added the pkg: astro Related to the core `astro` package (scope) label Jul 19, 2026
@codspeed

codspeed Bot commented Jul 19, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

✅ 21 untouched benchmarks


Comparing ocavue/data-store-json-parse (8fdcc52) with main (5a5337e)

Open in CodSpeed

@ocavue ocavue changed the title Emit the content data store as a JSON string instead of an object literal refactor: emit the content data store as a JSON string Jul 19, 2026
@ocavue ocavue changed the title refactor: emit the content data store as a JSON string refactor(astro): emit the content data store as a JSON string Jul 19, 2026
@ocavue ocavue changed the title refactor(astro): emit the content data store as a JSON string refactor: emit the content data store as a JSON string Jul 19, 2026
@ocavue
ocavue marked this pull request as ready for review July 19, 2026 06:03
@ocavue ocavue added the dependencies Pull requests that update a dependency file label Jul 19, 2026
@ematipico

Copy link
Copy Markdown
Member

I would appreciate some manual testing too.

@ocavue

ocavue commented Jul 21, 2026

Copy link
Copy Markdown
Contributor Author

I will do some manual testing and attach the report here.

@ocavue

ocavue commented Jul 31, 2026

Copy link
Copy Markdown
Contributor Author

Sorry for the late reply. I was doing something else in the past week.

I ran the manual tests. Both build, dev (including HMR) work fine based on my test.

@ocavue
ocavue merged commit 9f4c1da into main Jul 31, 2026
30 checks passed
@ocavue
ocavue deleted the ocavue/data-store-json-parse branch July 31, 2026 02:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dependencies Pull requests that update a dependency file pkg: astro Related to the core `astro` package (scope)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants