Skip to content

perf: skip Class.getName() when wrapping a returned object of a seen class - #2075

Draft
triniwiz wants to merge 1 commit into
mainfrom
perf/wrapper-class-cache
Draft

triniwiz wants to merge 1 commit into
mainfrom
perf/wrapper-class-cache

Conversation

@triniwiz

@triniwiz triniwiz commented Oct 31, 2026 •

Copy link
Copy Markdown
Member

What

When a Java method returns an object that has no JS wrapper yet, ObjectManager::CreateJSWrapper called Class.getName() in Java, copied the jstring into a std::string, replaced . with /, and then looked the class up again with FindClass for Link.

ObjectManager now remembers up to four runtime classes per declared type. Each is matched with IsSameObject, which runs no Java code, and the cached class name and global class are reused. On a miss the old path runs, with FindClass still after the wrapper is created. The cached jclass values come from JEnv's class cache, whose global refs are never deleted.

Measurements

Pixel 9 Pro emulator (arm64, headless), xplat-benchmarks NativeScript app, size M, release build, 5 interleaved rounds. Both runtimes were built from main with and without this change and #2076 (measured together). attached B/A:

Scenario attached per round
grid-dashboard 0.96 0.95 0.95 0.99 0.97 0.98
tree-fanout 0.96 1.02 0.93 0.92 0.96 1.00
flex-wrap-tiles 1.00
styled-cards 1.01
text-flow 1.00

The gain is small; most of the per-object cost is still getOrCreateJavaObjectID, which this does not touch.

Testing

  • :runtime:assembleRelease -Poptimized -Pabis=arm64-v8a builds; the runtime swapped into a 9.1.1 app ran every benchmark round.
  • The runtime test suite has not been run.

…class

Wrapping a Java object returned to JS called Class.getName() in Java,
copied the jstring, and looked the class up again with FindClass for Link.
ObjectManager now keeps up to four runtime classes per declared type,
matched with IsSameObject (no Java code runs), and reuses the class name
and global class. On a miss FindClass still runs after the wrapper is
created, as before.
@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