Skip to content

perf(runtime): cache the instance prototype per class meta - #535

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

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

Conversation

@triniwiz

Copy link
Copy Markdown
Member

What

ArgConverter::CreateJsWrapper only cached prototypes for JS-extended classes (ClassPrototypes). Every other native object returned to JS rebuilt its prototype on each wrap:

  • objc_getClass(meta->name())
  • the constructor template lookup
  • GetFunction
  • a new "prototype" V8 string and a property Get

Without extra protocols the constructor template is cached per meta, so its prototype never changes. MetaInstancePrototypes keeps it per meta; a wrap with no extra protocols now goes straight to SetPrototype. Wraps with extra protocols take the existing path.

Measurements

iPhone 17 Pro simulator, xplat-benchmarks NativeScript app, size M, 5 interleaved rounds. Both builds come from this branch, with and without the change. attached is the mount phase up to the views being attached, B/A:

Scenario attached
text-flow 0.97
flex-wrap-tiles 0.98
grid-dashboard 0.98
styled-cards 0.99
tree-fanout 0.99

Four of five rounds went the same way; one round was noisy in both directions. In a sampled profile of that app, this lookup chain was about 40% of CreateJsWrapper.

Testing

  • Simulator builds of NativeScript.framework, swapped into the benchmark app; every benchmark round ran to completion.
  • TestRunner not run yet.

CreateJsWrapper only had a prototype cache for JS-extended classes
(ClassPrototypes). Every other native object returned to JS rebuilt its
prototype on each wrap: objc_getClass(meta->name()), the constructor
template lookup, GetFunction, a new "prototype" string and a property Get.

Without extra protocols the constructor template is cached per meta, so
its prototype is fixed. MetaInstancePrototypes keeps it per meta and the
wrap goes straight to SetPrototype.
@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