Skip to content

Store the constant pool in typed arrays, about 8 MB less heap per javac VM - #60

Merged
Project516 merged 2 commits into
masterfrom
p516/cp-pack
Nov 6, 2026
Merged

Project516 merged 2 commits into
masterfrom
p516/cp-pack

Conversation

@Project516

Copy link
Copy Markdown
Owner

A library VM uses about 8 MB less heap after a javac compile. The constant pool now lives in typed arrays instead of one object per entry.

Each parsed class kept its constant pool as an array with one { tag, value, a, b } object per non-UTF-8 entry, about 156,000 objects in a javac VM. Now each class has:

  • tags, a Uint8Array,
  • ab, a Uint32Array holding the two u16 operands of each entry,
  • values, holding UTF-8 strings and numbers.

The interpreter, JIT and invokedynamic code read the arrays through cpTag, cpA, cpB and cpValue. cpEntry still builds an entry object for the few reflection natives that want one.

Heap after a forced gc, master to this branch, median of 3:

master this branch
hello world, restored from a boot snapshot 44.8 MB 42.0 MB
library VM after one javac compile 114.5 MB 106.6 MB

Time: whole runs (hello world start, a javac compile, the test suite) stay within run-to-run noise. In microbenchmarks, parsing is 3 to 5% slower, and constant pool reads during resolution are about 3 times faster.

Tests: pnpm typecheck and pnpm test pass.

@coderabbitai

coderabbitai Bot commented Nov 6, 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 26 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: 1f8d2354-2acd-415d-a009-7b5b9e4ff8a7
Commits

Reviewing files that changed from the base of the PR and between e0360df and 084b360.

Files selected for processing: 5

  • src/classfile.ts
  • src/indy.ts
  • src/jit.ts
  • src/jvm.ts
  • src/natives/npe.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.

The PR replaces the constant pool representation from an array of objects to three typed arrays (Uint8Array for tags, Uint32Array for packed a/b operands, and a regular array for UTF-8 strings and numeric values). This reduces heap usage by ~8 MB per javac VM. All five modified files (classfile.ts, indy.ts, jit.ts, jvm.ts, npe.ts) have been consistently updated to use the new accessor functions (cpTag, cpA, cpB, cpValue, utf8). The parsing logic correctly handles Long/Double double-slot entries and index 0. No bugs or logic errors are present in the diff.


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

@Project516
Project516 merged commit 1ddcaf9 into master Nov 6, 2026
16 checks passed
@Project516
Project516 deleted the p516/cp-pack branch November 6, 2026 02:35
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