Skip to content

feat: add HeapCodeStatistics API#1921

Merged
bartlomieju merged 5 commits intomainfrom
feat/heap-code-statistics
Mar 4, 2026
Merged

feat: add HeapCodeStatistics API#1921
bartlomieju merged 5 commits intomainfrom
feat/heap-code-statistics

Conversation

@bartlomieju
Copy link
Member

Summary

  • Expose Isolate::get_heap_code_and_metadata_statistics() wrapping V8's GetHeapCodeAndMetadataStatistics
  • Add HeapCodeStatistics struct with code_and_metadata_size, bytecode_and_metadata_size, external_script_source_size, and cpu_profiler_metadata_size
  • Needed to implement Node.js v8.getHeapCodeStatistics() in Deno

Test plan

  • Added test in tests/test_api.rs (heap_code_statistics) that verifies the API returns valid statistics before and after running JS code

🤖 Generated with Claude Code

bartlomieju and others added 3 commits March 4, 2026 11:23
Expose `Isolate::get_heap_code_and_metadata_statistics()` which wraps
V8's `GetHeapCodeAndMetadataStatistics`. Returns a `HeapCodeStatistics`
struct with code_and_metadata_size, bytecode_and_metadata_size,
external_script_source_size, and cpu_profiler_metadata_size.

This is needed to implement Node.js `v8.getHeapCodeStatistics()` in Deno.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
code_and_metadata_size may be 0 on a fresh isolate before any JS is
compiled, depending on the platform and V8 version.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
code_and_metadata_size tracks JIT-compiled code, which may be 0 if V8
only uses the interpreter for simple scripts. Assert non-decreasing
instead of > 0.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
…ual mirror

Use the real V8 HeapCodeStatistics type via bindgen, matching the
pattern used by HeapStatistics and HeapSpaceStatistics.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@bartlomieju bartlomieju enabled auto-merge (squash) March 4, 2026 11:51
@bartlomieju bartlomieju merged commit 94aca69 into main Mar 4, 2026
20 checks passed
@bartlomieju bartlomieju deleted the feat/heap-code-statistics branch March 4, 2026 12:15
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.

2 participants