Skip to content

perf(android): create wrappers on the class prototype without a JSObject construction - #126

Open
ammarahm-ed wants to merge 1 commit into
perf/jni-06-return-classfrom
perf/jni-07-wrapper-prototype
Open

ammarahm-ed wants to merge 1 commit into
perf/jni-06-return-classfrom
perf/jni-07-wrapper-prototype

Conversation

@ammarahm-ed

Copy link
Copy Markdown
Collaborator

A wrapper for a returned Java object was built by constructing a JSObject through its constructor callback, then setting an own constructor property and the class prototype on it. The class prototype already carries both the runtime marker and constructor, so the wrapper is now a plain object created directly with that prototype: no construction through the engine's callback path and no extra own property. This is the same change in the Node-API and the direct runtime (MetadataNode::CreateJSWrapper).

Results

V8 release build on a Sony SO-01M (Android 11, arm64), AOT-compiled with cmd package compile -m speed. One warm-up launch is discarded, then 5 launches; values are the median ns per call.

Case Node-API before after Δ Direct before after Δ
Return a new object 28,552 28,339 -1% 22,441 19,349 -14%
Call a method on a new object 36,425 35,895 -1% 31,500 28,239 -10%
Return a Date Object 28,744 28,710 -0% 23,343 20,413 -13%
Return this 1,320 1,338 +1% 1,327 1,312 -1%

The direct runtime is 10–14% faster on the rows that create a wrapper. Node-API is flat, within noise: there the construction was not the dominant cost. Return this returns an existing wrapper and does not reach this code.

All cases
Case Node-API before after Δ Direct before after Δ
Void Method on instance 664 631 -5% 606 584 -4%
Field on instance 810 807 -0% 845 894 +6%
Int Field on instance 376 365 -3% 372 395 +6%
Get Static Field 826 836 +1% 846 856 +1%
Void Static Method 317 309 -3% 304 299 -2%
multiply(a, b) 528 478 -10% 511 514 +0%
Pass and return string 1,208 1,154 -4% 1,184 1,164 -2%
Return a String 808 821 +2% 781 746 -5%
Return an Int 335 330 -2% 304 306 +1%
Pass a String 677 660 -2% 657 654 -0%
Return a Boolean 326 316 -3% 300 296 -1%
Return a Double 400 392 -2% 364 388 +7%
Pass an Int 422 393 -7% 418 407 -3%
Pass a Double 402 389 -3% 409 412 +1%
Pass a Boolean 502 476 -5% 429 432 +1%
Return an Int Array 27,806 27,547 -1% 18,681 18,232 -2%
Pass an Int Array 3,266 3,051 -7% 4,138 3,983 -4%
Return a String Array 28,082 27,902 -1% 20,078 20,155 +0%
Pass a String Array 5,468 5,354 -2% 6,578 6,641 +1%
Return a Double Array 26,814 26,756 -0% 19,978 19,726 -1%
Pass a Double Array 3,214 3,049 -5% 3,952 3,901 -1%
Return a Boolean Array 25,587 25,451 -1% 19,182 18,996 -1%
Pass a Boolean Array 3,102 2,870 -7% 3,760 3,660 -3%
Int Array[0] read 343 348 +2% 250 245 -2%
String Array[0] read 787 777 -1% 666 671 +1%
Double Array[0] read 435 465 +7% 361 336 -7%
Boolean Array[0] read 352 339 -4% 234 234 -0%
Int Array[0] write 459 476 +4% 364 360 -1%
String Array[0] write 1,138 1,163 +2% 1,058 1,035 -2%
Double Array[0] write 476 468 -2% 372 374 +1%
Boolean Array[0] write 466 464 -0% 372 369 -1%
Return a Date Object 28,744 28,710 -0% 23,343 20,413 -13%
Pass a Date Object 3,865 3,853 -0% 3,657 3,656 -0%
Invoke void callback 7,288 7,647 +5% 6,887 7,214 +5%
Instance add(a, b) 854 840 -2% 816 806 -1%
Pass and return non-ASCII string 1,189 1,161 -2% 1,177 1,189 +1%
Pass and return 1KB string 5,073 5,166 +2% 5,133 5,064 -1%
Return a Char 361 351 -3% 355 341 -4%
Return this 1,320 1,338 +1% 1,327 1,312 -1%
Return a new object 28,552 28,339 -1% 22,441 19,349 -14%
Call a method on a new object 36,425 35,895 -1% 31,500 28,239 -10%
Pass a 16 Int Array 4,543 4,138 -9% 5,141 4,935 -4%
Pass a 16 Double Array 5,304 4,803 -9% 5,780 5,761 -0%
Invoke int callback 10,346 10,298 -0% 11,232 12,617 +12%
Invoke string callback 8,676 8,837 +2% 8,262 8,125 -2%
Native heap after run (MB) 257 MB 268 MB +4% 208 MB 173 MB -17%

Only V8 was built and run.

@coderabbitai

coderabbitai Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

Run configuration

  • Source mode: Auto
  • Repository: Unavailable
  • Branch: Unavailable
  • File: No configuration file from this repository applied
  • Commit: Unavailable
  • Layers: Organization UI
  • Review profile: CHILL
  • Plan: Advanced
  • Run ID: 4c538c72-8a10-4782-a7fa-3bc2af1d5bd9

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
  • 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

@ammarahm-ed
ammarahm-ed added this pull request to stack #121 November 9, 2026 06:44

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