Skip to content

Store UTF-8 constants in the constant pool as plain strings - #41

Merged
Project516 merged 3 commits into
masterfrom
p516/compact-cp
Nov 4, 2026
Merged

Project516 merged 3 commits into
masterfrom
p516/compact-cp

Conversation

@Project516

Copy link
Copy Markdown
Owner

Every constant pool entry was a { tag, value, a, b } object, and most entries are UTF-8 strings: names, descriptors, signatures and attribute names. A live VM restored from a boot snapshot held about 128,000 of these objects.

UTF-8 entries are now stored as the string itself. cpEntry(cp, i) returns an entry object for the other kinds and wraps a string when a caller needs one. utf8(cp, i) reads the string directly. Every reader of the constant pool goes through one of the two: the interpreter's resolution in src/jvm.ts, the JIT, invokedynamic and condy, reflection, and the helpful NullPointerException messages.

Measured on a small ARM board, median of eight alternating runs:

Measurement Before After
JS heap of a live VM restored from a snapshot 42.96 MB 38.79 MB
Hello world peak RSS 154,312 KiB 145,696 KiB
javac (one file) peak RSS 359,904 KiB 337,440 KiB
Hello world from a snapshot 0.515 s 0.500 s
Hello world, full boot 1.320 s 1.290 s
javac, one file 7.41 s 6.73 s

The times are within noise. The memory is not: about 4 MB (10%) less heap per VM.

Checks:

  • New test/classfile.test.ts cases for UTF-8 entries stored as strings and wrapped by cpEntry.
  • pnpm typecheck and pnpm test pass (145 tests), boot snapshot restore included.
  • The browser self-test passes on a fresh and on a reused profile.

Noticed, not fixed:

  • Member and code records, and the pack index's { image, at } offsets, are the next largest groups of small objects. Their savings were not measured.

@coderabbitai

coderabbitai Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Warning

Review limit reached

You've used all free OSS reviews for now. Wait for the free limit to reset to keep reviewing this public repository.

Next included review available in 58 minutes.

Check out review usage here.

View limit details

Limit details: You’ve used the included review currently available.

Learn how review limits work.

Review configuration:

Run configuration
  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: ASSERTIVE
  • Plan: Advanced
  • Run ID: cf887329-380d-4847-8e91-6b608f53089b
Commits

Reviewing files that changed from the base of the PR and between 343d3fc and 37a3ef7.

Files selected for processing: 7
  • src/classfile.ts
  • src/indy.ts
  • src/jit.ts
  • src/jvm.ts
  • src/natives/npe.ts
  • src/natives/reflect.ts
  • test/classfile.test.ts
  • Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

Share

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR changes UTF-8 constant pool entries from objects to plain strings, reducing memory usage by ~10% (4 MB per VM). All constant pool readers now go through cpEntry() (which wraps strings on demand) or utf8() (which reads strings directly). The change is applied consistently across the interpreter, JIT, invokedynamic, reflection, and NPE message generation. Tests pass including boot snapshot restore and browser self-tests.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 enabled auto-merge (squash) November 4, 2026 22:50

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR changes the constant pool representation to store UTF-8 entries as plain strings instead of {tag, value, a, b} objects, reducing VM heap by ~10%. A new cpEntry(cp, i) function wraps a string in a CpEntry object when callers need one, while utf8(cp, i) reads the string directly. All constant pool readers across the interpreter, JIT, invokedynamic, reflection, and NPE message builder have been updated to use these two functions. Tests pass including boot snapshot restore.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@project516-review-bot project516-review-bot Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR changes UTF-8 constant pool entries to be stored as plain strings instead of objects, reducing memory usage by ~10% (4 MB per VM). All constant pool access sites across the interpreter, JIT, indy, reflection, and NPE message builder are updated to use the new cpEntry() helper which wraps strings on demand. Tests and typecheck pass.


review-bot, model nvidia/nemotron-3-ultra-550b-a55b:free, verdict approve

@Project516
Project516 merged commit 1c7e4f2 into master Nov 4, 2026
16 checks passed
@Project516
Project516 deleted the p516/compact-cp branch November 4, 2026 23:27
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.

1 participant

⌂ Proxy