Skip to content

perf: lazy JSON bridge for Native→Kotlin callKotlin (OHOS + iOS) - #1599

Open
ruifanyuan wants to merge 2 commits into
Tencent-TDS:mainfrom
ruifanyuan:feat/call_kotlin_perf
Open

perf: lazy JSON bridge for Native→Kotlin callKotlin (OHOS + iOS)#1599
ruifanyuan wants to merge 2 commits into
Tencent-TDS:mainfrom
ruifanyuan:feat/call_kotlin_perf

Conversation

@ruifanyuan

@ruifanyuan ruifanyuan commented Aug 5, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Speed up Native→Kotlin callKotlin for large/unread JSON by passing structured payloads instead of stringify + parse.
  • OHOS: Map/Array → NATIVE_JSON (shared_ptr cJSON) → LazyCJsonMap inside final JSONObject; Create pageData and Update/SendEvent use the same path (no JSON.stringify / toString()).
  • iOS: Pass NSDictionary through ObjC; wrap at KSP entry via toKotlinBridgeArgLazyNSDictionaryMap before BridgeManager (parallel to OHOS toAny).
  • Keep hot-path extras that measured well: instanceId cache (A), KSP entry without per-call lambda (B).
  • Debug-only CallKotlinPerf harness + demo page for Fire/Update/Callback string vs lazy.

Bench (unread cpp_callKotlin)

OHOS device — Fire string → lazy:

  • 1KB: 190µs → 68µs (~3×)
  • 64KB: 7.9ms → 61µs (~130×)
  • 3MB: 354ms → 61µs (~5800×)
    iOS simulator — Fire string → lazy:
  • 1KB: ~19µs → 1.3µs
  • 64KB: ~1ms → 1.3µs
  • 3MB: ~57ms → 1.3µs

Test plan

  • OHOS Debug HAP: open CallKotlinPerfPage → hilog CallKotlinPerf shows NESTED_LIFECYCLE / PHASES_CPP / DONE
  • iOS Debug: same page → console tag CallKotlinPerf completes full fire/update/callback sweep
  • Smoke Create/Update with page params and lifecycle events (Record/dict, not only strings)
  • Release build: confirm CallKotlinPerfTestModule omitted (NDEBUG / non-DEBUG)

ruifanyuan and others added 2 commits August 4, 2026 16:09
Keep instanceId cache (~10% LAYOUT) and KSP OHOS entry hot path (~2× small
LAYOUT). Pass Map/Array as NATIVE_JSON (shared_ptr cJSON) so unread payloads
stay flat; JSONObject stays final via LazyCJsonMap. Module registry is shared
in libkuikly.so; CallKotlinPerfTestModule is Debug/NDEBUG-only.

Device bench (LNG0223C13000049), cpp_callKotlin unread:
- LAYOUT: ~35µs
- FIRE string vs lazy map: 1KB 188→61µs (~3×); 64KB 7.8ms→61µs (~128×);
  3MB 368ms→72µs (~5100×)

Co-authored-by: Cursor <cursoragent@cursor.com>
iOS: pass NSDictionary through ObjC; wrap at KSP entry via toKotlinBridgeArg
(LazyNSDictionaryMap) before BridgeManager — same shape as OHOS toAny.
OHOS: Create pageData and Update/SendEvent pass structured Map/Record
(NATIVE_JSON) instead of JSON.stringify.

Bench (unread cpp_callKotlin):
- OHOS device Fire string→lazy: 1KB 190→68µs; 64KB 7.9ms→61µs; 3MB 354ms→61µs
- iOS sim Fire string→lazy: 1KB ~19→1.3µs; 64KB ~1ms→1.3µs; 3MB ~57ms→1.3µs

DEBUG CallKotlinPerf harness covers fire/update/callback on both platforms.

Co-authored-by: Cursor <cursoragent@cursor.com>
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