Skip to content

Conversation

@kedarvartak
Copy link
Contributor

Changes

  • Fixed OOM errors when using CJK fonts by optimizing virtual module code generation in the Fonts API.
  • Replaced JSON.stringify(Array.from(map.entries())) with programmatic map building using individual set() calls.
  • This prevents excessive memory allocation during build when processing fonts with large character sets (CJK fonts can have 10,000+ characters).

Testing

  • Verified existing font tests still pass with the new code generation approach.
  • The generated virtual module output remains functionally identical, just with different serialization strategy.

Docs

  • No documentation changes needed.
@changeset-bot
Copy link

changeset-bot bot commented Jan 28, 2026

⚠️ No Changeset found

Latest commit: 93e823b

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.

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 Jan 28, 2026
Copy link
Member

@ematipico ematipico left a comment

Choose a reason for hiding this comment

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

This code change isn't enough. We now exporting different bindings from the virtual module, but you didn't update all the consumers that use the new variables. In fact, the code doesn't build and I bet tests will breawk

Copy link
Member

@Fryuni Fryuni left a comment

Choose a reason for hiding this comment

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

Besides this being broken since it didn't update the consumer side of this code, this won't really reduce the memory usage. The memory is not going into the arrays, those are just holding references to the elements that already exist in the map so the arrays only allocate space for their pointers, which is negligible mostly negligible.

The large memory allocation performed in this function is for the enormous string that gets generated, and that is not changing with this PR. In fact it is now an even bigger string, built with even more allocations since due to being done in pieces.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pkg: astro Related to the core `astro` package (scope)

3 participants