Skip to content

refactor(runtime): consolidate engine backends and harden ownership - #73

Open
DjDeveloperr wants to merge 4 commits into
refactorfrom
agent/refactor-engine-backends
Open

refactor(runtime): consolidate engine backends and harden ownership#73
DjDeveloperr wants to merge 4 commits into
refactorfrom
agent/refactor-engine-backends

Conversation

@DjDeveloperr

@DjDeveloperr DjDeveloperr commented Aug 20, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • consolidate runtime teardown and ownership handling across direct-engine and Node-API backends
  • keep direct-engine marshalling concrete and hot-path-specific while sharing lifecycle infrastructure
  • remove duplicate Android QuickJS/mimalloc, JSC, and V8 sources plus generated binaries, archives, samples, and vendored allocator collateral
  • generate one shared signature-dispatch table for every backend
  • harden circular conversion, weak references, finalizers, worker shutdown, JNI refs, timers, nested FFI layouts, callback lifetimes, and per-runtime caches
  • package the complete shared Objective-C bridge for React Native and add package tests

The committed range is 396 files, 4,104 insertions, and 86,265 deletions: net -82,161 lines.

Architecture

The Node-API backend remains the ownership/lifecycle reference. Direct backends now use a small shared cleanup registry and shared bridge organization, but engine-native value marshalling stays in the concrete V8, JSC, QuickJS, and Hermes implementations to preserve their faster call paths. Hermes native structs use JSI NativeState instead of a hidden JavaScript property.

Memory validation

  • macOS CLI builds: V8, QuickJS, JSC, Hermes x direct/Node-API
  • semantic ownership matrix: 288/288 across all eight configurations with GSD enabled and disabled
  • post-CI ownership/identity/initializer regression matrix green across all eight configurations with GSD enabled and disabled
  • QuickJS direct post-fix semantics rerun: 15/15 GSD on and 15/15 GSD off; the former teardown crash path also passed 10 consecutive runs in each mode
  • full RSS stress reports green across all eight configurations
  • four-wave Objective-C wrapper plateau test green across all eight configurations
  • worker lifecycle, worker error, main-env shutdown, JS-function finalization, selector-group finalization, nested FFI, pointer buffer, unmanaged transfer, and circular JS/native tests included
  • React Native package tests pass
  • FFI boundary audit passes

JSC Node-API previously allocated a new JSClassRef for every weak reference/wrapper. Sharing one class per info type reduced representative RSS from 278.3 MB to 62.4 MB for wrapper churn and from 162.4 MB to 68.9 MB for mixed stress. The final focused plateau rerun was 49.0 MB.

Window-bearing stress tests are excluded by default. They are opt-in with MEMTEST_WINDOW_TESTS=1, and the AppKit cases construct borderless windows offscreen.

Performance

Median microseconds per call, five alternating GSD-on/off runs:

Runtime GSD NSDate.date NSDate.double NSDate.primitive NSString.compare CFAbsoluteTime CGPoint.get CGPoint.set CGPoint.construct
V8 direct on 9.489 6.241 0.070 0.117 0.073 0.043 0.113 0.377
V8 direct off 9.446 6.220 0.084 0.212 0.072 0.042 0.107 0.377
V8 N-API on 69.843 0.229 0.254 1.014 0.034 0.268 0.228 0.442
V8 N-API off 69.475 0.316 0.279 1.254 0.061 0.270 0.226 0.443
QuickJS direct on 5.277 5.380 0.102 0.174 0.098 0.044 0.073 0.279
QuickJS direct off 5.415 5.470 0.110 0.256 0.099 0.044 0.073 0.272
QuickJS N-API on 68.735 0.174 0.238 0.774 0.055 0.600 1.179 11.088
QuickJS N-API off 68.446 0.274 0.261 1.018 0.086 0.602 1.224 11.480
JSC direct on 8.991 8.911 0.178 0.302 0.130 0.087 0.172 0.462
JSC direct off 9.084 8.881 0.183 0.429 0.125 0.092 0.186 0.465
JSC N-API on 74.139 0.527 0.707 4.523 0.268 0.480 0.976 1.715
JSC N-API off 105.815 0.738 0.785 5.100 0.279 0.450 0.907 1.682
Hermes direct on 4.276 4.020 0.186 0.263 0.158 0.099 0.196 2.504
Hermes direct off 4.369 4.107 0.187 0.337 0.157 0.098 0.193 2.504
Hermes N-API on 134.547 0.337 0.265 1.025 0.118 0.136 0.241 0.755
Hermes N-API off 99.975 0.440 0.287 1.241 0.145 0.135 0.239 0.758

NSDate.double is dateWithTimeIntervalSince1970, NSDate.primitive is timeIntervalSince1970, and NSString.compare is compareOptions.

Direct-engine medians remain comparable to or better than the pre-change baselines. Allocation-heavy NSDate.date is noisy in Node-API configurations because finalizer and GC work is included. JSC Node-API's bounded-memory fix intentionally replaces the old leaky allocation behavior; isolated reruns put that case around 111-114 us/call.

Android and packaging

  • native C++ targets built for Debug and RelWithDebInfo across four ABIs for QuickJS, QuickJS-NG, JSC, Hermes, PrimJS, V8 10, V8 11, and V8 13
  • JSC native targets were rebuilt across all four ABIs after the final shared-class RAII change
  • React Native no-pack staging contains the full host_objects bridge and both generated dispatch tables
  • metadata generator builds and its normalized source hash matches the built generator

The aggregate Android Gradle invocation still reaches unrelated Java/Kotlin tasks and fails under the machine's Java 25 installation. Native CMake tasks are green; the repository documents JDK 17 as the supported toolchain.

Artifact audit

  • no added jars, archives, native binaries, node_modules, build directories, or generated package staging
  • no absolute worktree or temporary paths in committed files
  • zero Git LFS objects to push; all changed LFS entries are deletions

@coderabbitai

coderabbitai Bot commented Aug 20, 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

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro Plus

Run ID: 2963b8a8-e1aa-4927-9721-36d8b545c3d0

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

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

Comment @coderabbitai help to get the list of available commands.

@DjDeveloperr
DjDeveloperr marked this pull request as ready for review August 20, 2026 16:17
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