Skip to content

perf: optimize generated native dispatch#33

Open
DjDeveloperr wants to merge 16 commits into
mainfrom
perf/hermes-direct-layer-optimizations
Open

perf: optimize generated native dispatch#33
DjDeveloperr wants to merge 16 commits into
mainfrom
perf/hermes-direct-layer-optimizations

Conversation

@DjDeveloperr
Copy link
Copy Markdown
Collaborator

Summary

  • Adds engine-direct native dispatch paths so V8, Hermes, QuickJS, and JSC can bypass the generic Node-API call path for generated Objective-C/C function dispatch while keeping the Node-API backend available for non-direct builds.
  • Extends generated signature dispatch with engine-specific backends, direct return handling, Hermes frame-argument dispatch, and fast block invoke support.
  • Optimizes bridge hot paths: leaner primitive/object marshalling, cached receiver/object/selector lookups, direct function/block invocation, and Hermes NSArray/NSMutableArray indexed access without the Proxy path for normal arrays.
  • Adds/updates the Objective-C dispatch benchmark harness for same-harness comparisons across NAPI engines and legacy iOS V8 AOT on/off.

Benchmark Results

Command family: node benchmarks/objc-dispatch/run.js --iterations 250000 using the same simulator/harness for all rows.

runtime total ms vs best vs legacy AOT on
v8 gsd-on 392.30 0.00 -52.13%
hermes gsd-on 437.71 +45.40 -46.59%
quickjs gsd-on 484.62 +92.32 -40.87%
v8 gsd-off 491.81 +99.51 -39.99%
hermes gsd-off 524.35 +132.04 -36.02%
quickjs gsd-off 535.76 +143.45 -34.63%
jsc gsd-on 547.74 +155.43 -33.17%
jsc gsd-off 594.84 +202.54 -27.42%
legacy aot-on 819.54 +427.24 baseline
legacy aot-off 942.25 +549.95 +14.97%

GSD deltas:

target on total ms off total ms win ms win %
v8 GSD 392.30 491.81 99.51 25.37%
hermes GSD 437.71 524.35 86.64 19.79%
quickjs GSD 484.62 535.76 51.13 10.55%
jsc GSD 547.74 594.84 47.10 8.60%
legacy AOT 819.54 942.25 122.71 14.97%

Result files:

  • build/benchmarks/objc-dispatch/results-2026-05-22T19-44-10-380Z.json
  • build/benchmarks/objc-dispatch/results-2026-05-22T19-46-55-756Z.json
  • build/benchmarks/objc-dispatch/results-2026-05-22T19-48-29-266Z.json
  • build/benchmarks/objc-dispatch/results-2026-05-22T19-49-26-650Z.json
  • build/benchmarks/objc-dispatch/results-2026-05-22T19-50-11-344Z.json

Validation

  • git diff --check origin/main..HEAD
  • IOS_TEST_ENGINE=hermes IOS_TEST_TIMEOUT_MS=900000 IOS_BUILD_TIMEOUT_MS=900000 npm run test:ios
    • SUCCESS: 705 specs, 0 failures, 14 skipped, 0 disabled
  • Built and benchmarked NAPI iOS runtime for V8, Hermes, QuickJS, and JSC simulator engines.
  • Built and benchmarked legacy iOS V8 runtime with AOT on/off.

Review Notes

  • HostObject method dispatch was investigated and rejected because method property callbacks were dramatically slower than the optimized wrapper/prototype path.
  • Hermes array optimization keeps placeholder arrays on the Proxy path and uses prototype numeric accessors only for initialized arrays.
  • Direct paths are compile-gated per engine/backend; the generic Node-API path remains for non-direct/non-engine builds.

@DjDeveloperr DjDeveloperr marked this pull request as ready for review May 23, 2026 07:19
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