[codex] Performance experiment: bind HybridObject functions to native instances - #1648
Draft
mrousavy wants to merge 3 commits into
Draft
[codex] Performance experiment: bind HybridObject functions to native instances#1648mrousavy wants to merge 3 commits into
mrousavy wants to merge 3 commits into
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub. 1 Skipped Deployment
|
Member
Author
|
@nitro-modules-bot please test performance |
This comment has been minimized.
This comment has been minimized.
Member
Author
|
@nitro-modules-bot please test performance |
Member
Author
|
@nitro-modules-bot please test performance |
Performance ReportiOS
All Benchmarks
Android
All Benchmarks
Benchmarking Code Diff Raw measurements and artifactsRaw measurements: performance-report-1 (JSON artifact). Run 34414142495, attempt 1. Download requires GitHub access. Android: measurements, attempt 1, apps, attempt 1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is a performance experiment, enabled for every newly created HybridObject on this branch. It tests the equivalent of binding each instance's methods and accessors to its native receiver: resolve the native type once during creation, capture a typed
shared_ptrin each HostFunction, and call through that pointer. Repeated calls skip the JS receiver/NativeState lookup, RTTI downcast, and temporary receivershared_ptrcopies. Native virtual methods still use normal C++ virtual dispatch.The instance gets its own methods, getters, setters, and raw JSI methods. The shared prototype remains intact, derived registrations take precedence, and argument conversion, argument-count checks, and exception translation remain shared with the original path. The existing performance suite exercises this path without benchmark or codegen changes. Removing the
bindHybridFunctions(...)call inHybridObject::toObject()restores the original dispatch path.This is intentionally experimental and not ready for production: creation allocates functions per instance, function identity and own-property enumeration change, and bound functions retain the native object and remain callable after
dispose()clears NativeState. Raw JSI methods bind the native receiver but still receive the caller's JSthisValue.The test utilities identify HybridObjects by prototype ancestry, since bound function identity differs per instance. The 55,000-object GC tests yield between batches to keep harness heartbeats responsive. External-memory tests collect earlier garbage before measuring global-counter deltas and retain the exact one-megabyte assertions. Benchmark receivers allow 20 minutes for a case; the fixed operation counts, all warmups/samples, and timed regions remain unchanged so creation overhead stays visible.
Validation:
git diff --checkpassed.18e254bfa, including Android default/ASan and iOS default/ASan/TSan harness variants.18e254bfa: 46 cases per platform across four baseline/head pairs, with matching suite hashes. Aggregation, PR report publication, and Bencher history publication all succeeded.Performance results from the CI iOS simulator and Android emulator, comparing
201794bfto18e254bf(full report):simpleFunc()addNumbers()create()The experiment reduces repeated-call overhead, with a large creation cost for the benchmark HybridObjects, which expose hundreds of functions. Swift and Kotlin
simpleFunc()times fell by 45.70% and 47.89%; their creation times rose to 126.80 µs and 135.30 µs respectively. These are results from this CI run, not physical-device measurements.