Skip to content

perf: ArrayBuffer.from without the isDirect() call - #2076

Draft
triniwiz wants to merge 1 commit into
mainfrom
perf/arraybuffer-from
Draft

triniwiz wants to merge 1 commit into
mainfrom
perf/arraybuffer-from

Conversation

@triniwiz

Copy link
Copy Markdown
Member

What

ArrayBuffer.from(byteBuffer) called ByteBuffer.isDirect() in Java to choose between the direct and copying paths. GetDirectBufferAddress already returns null for a heap buffer, so the null check now picks the path and the Java call is gone. A direct buffer whose address is unavailable falls back to the copying path, which works for both kinds.

The nativeObject key set on the returned buffer is now one internalized v8::Eternal string, so a new string is no longer made on every call.

Measurements

Measured together with #2075 (same setup and numbers there): grid-dashboard and tree-fanout attached 0.96, other scenarios flat. This part on its own removes one JNI call into Java and one string allocation per ArrayBuffer.from.

Testing

  • :runtime:assembleRelease -Poptimized -Pabis=arm64-v8a builds; ran in the benchmark app as above.
  • The runtime test suite has not been run.

GetDirectBufferAddress already returns null for a heap buffer, so the
Java isDirect() call is not needed to pick the path. The "nativeObject"
key is now one internalized string instead of a new string per call.
@coderabbitai

coderabbitai Bot commented Oct 31, 2026

Copy link
Copy Markdown

Important

Draft PR not reviewed

Draft PRs are not automatically reviewed by default.

  • Trigger a manual review

To automatically review draft PRs, update your CodeRabbit configuration:

reviews:
  auto_review:
    drafts: true
  • 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

This branch has not been deployed

No deployments
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