Skip to content

Drop parsed member records after linking, about 1 to 3 MB less heap per VM - #55

Merged
Project516 merged 3 commits into
masterfrom
p516/vm-memory
Nov 5, 2026
Merged

Project516 merged 3 commits into
masterfrom
p516/vm-memory

Conversation

@Project516

Copy link
Copy Markdown
Owner

Each VM keeps a little less heap. After linking, the runtime JField and JMethod objects hold everything the VM needs from a class's fields and methods, but the parser's member records stayed reachable from the class file object. Linking now drops them. Only the linking loop read them, and every class is parsed fresh and linked once, so nothing reads them later.

Measured here (Pi 5), heap used after a forced collection, two runs each against master:

master this PR saved
hello world, restored from the boot snapshot 45.90 MB 44.56 MB 1.34 MB
library VM after one javac compile 121.45 MB 118.46 MB 3.00 MB

Time is unchanged: hello world start 323 / 293 ms (median), library start 313 / 286 ms, one javac compile 5.77 / 5.21 s, pnpm test 308.7 / 310.6 s over three runs each.

pnpm typecheck and pnpm test pass, including the boot and warm snapshot tests.

Noticed, not fixed:

  • Constant pool entries remain the next big item: one plain object per entry, which shows up as about 4 to 12 MB of generic Object in heap snapshots. Packing them into typed arrays would need care to keep resolution as fast.

@coderabbitai

coderabbitai Bot commented Nov 5, 2026 •

Copy link
Copy Markdown

Explain Change →

Important

Review skipped

Review was skipped as selected files did not have any reviewable changes.

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: 16aee778-d7d6-4719-a1f4-c10439e535ad
Commits

Reviewing files that changed from the base of the PR and between 0f8bf28 and 23e1b38.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • Trigger review

No actionable comments were generated in the recent review.

Summary

Summary by CodeRabbit

  • Improvements
    • Class linking now avoids retaining parsed member data after runtime setup is complete. This internal change does not alter the public API or expected application behavior. No user-facing features or behavior changes are included in this update.

JVM.defineLinked now empties the parsed ClassFile’s fields and methods arrays after creating runtime members and populating the class’s method map.

Changes: Class Definition

Layer / File(s) Summary
Runtime member transfer
src/jvm.ts
After creating runtime fields and methods and populating the method map, defineLinked empties the parsed ClassFile’s fields and methods arrays.

Estimated code review effort: 1 (Trivial) | ~3 minutes

Change: Refactor

Merge Risk: Minimal · previous review 0f8bf

The cleanup appears mergeable after normal checks, with no identified behavioral regression.

Pre-merge checks: Passed 5

Check name Status Explanation
Title check Passed The title names the main change: parsed member records (fields and methods) are dropped after linking, which lowers heap use per VM. The raw summary confirms that defineLinked clears the ClassFile fie…
Description check Passed The description explains the change. It says linking now drops the parser's member records that stayed reachable from the class file object, and that only the linking loop read them. It also gives hea…
Docstring Coverage Passed No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentat…
Linked Issues check Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check Passed Check skipped because no linked issues were found for this pull request.
Full details: Title check

Explanation

The title names the main change: parsed member records (fields and methods) are dropped after linking, which lowers heap use per VM. The raw summary confirms that defineLinked clears the ClassFile fields and methods arrays after creating JField and JMethod objects. The title is specific and matches the changeset. It is slightly long at 74 characters, but it is clear.

Full details: Description check

Explanation

The description explains the change. It says linking now drops the parser's member records that stayed reachable from the class file object, and that only the linking loop read them. It also gives heap and timing measurements from before and after the change, notes that typecheck and tests pass, and mentions constant pool entries as a follow-up item. It is directly related to the changeset.

Full details: Docstring Coverage

Explanation

No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 1 files.

Finishing Touches

Generate docstrings

  • Commit to this branch
  • Create a new PR
Simplify code

  • Commit to this branch
  • Create a new PR
  • 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

A rabbit saw fields hop away,
And methods follow without delay.
Runtime members took their place,
The parsed arrays cleared the space.
The class now rests, neat as can be.

Recent review info

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: e258935b-812e-460e-84b5-0708d64640de
Commits

Reviewing files that changed from the base of the PR and between cac6f05 and 0f8bf28.

Files selected for processing: 1

  • src/jvm.ts

Included review availability: This review used your included allowance. Your plan provides up to 1 included review per hour; 0 remain after this review.

Recent review details

Context from checks skipped due to timeout: 10

  • GitHub Check: CodeRabbit
  • GitHub Check: jtreg / run (8)
  • GitHub Check: jtreg / run (1)
  • GitHub Check: jtreg / run (6)
  • GitHub Check: jtreg / run (3)
  • GitHub Check: jtreg / run (4)
  • GitHub Check: jtreg / run (7)
  • GitHub Check: jtreg / run (5)
  • GitHub Check: jtreg / run (2)
  • GitHub Check: test
Additional comments: 1

src/jvm.ts: 1

340-342: LGTM!

@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 clears the parsed field and method arrays on the class file object after linking, since the runtime JField and JMethod objects now own all needed metadata. This reduces heap usage by 1–3 MB per VM with no performance regression.


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.

The PR discards the temporary parsed member records (fields and methods) from the ClassFile object after linking, reducing heap usage by about 1–3 MB per VM. The runtime JField and JMethod objects now hold all needed metadata, and the change does not affect start‑up or compile times.


review-bot, model cohere/north-mini-code:free, verdict approve

@Project516
Project516 merged commit d6b2c5d into master Nov 5, 2026
16 checks passed
@Project516
Project516 deleted the p516/vm-memory branch November 5, 2026 21:34
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