perf: lazy JSON bridge for Native→Kotlin callKotlin (OHOS + iOS) - #1599
Open
ruifanyuan wants to merge 2 commits into
Open
perf: lazy JSON bridge for Native→Kotlin callKotlin (OHOS + iOS)#1599ruifanyuan wants to merge 2 commits into
ruifanyuan wants to merge 2 commits into
Conversation
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>
ruifanyuan
requested review from
elixxli,
etkmao,
iPel,
luoyibu,
zealotchen0 and
zenipchen
as code owners
August 5, 2026 03:14
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.
Summary
callKotlinfor large/unread JSON by passing structured payloads instead of stringify + parse.NATIVE_JSON(shared_ptr cJSON) →LazyCJsonMapinside finalJSONObject; Create pageData and Update/SendEvent use the same path (noJSON.stringify/toString()).NSDictionarythrough ObjC; wrap at KSP entry viatoKotlinBridgeArg→LazyNSDictionaryMapbeforeBridgeManager(parallel to OHOStoAny).CallKotlinPerfharness + demo page for Fire/Update/Callback string vs lazy.Bench (unread
cpp_callKotlin)OHOS device — Fire string → lazy:
iOS simulator — Fire string → lazy:
Test plan
CallKotlinPerfPage→ hilogCallKotlinPerfshowsNESTED_LIFECYCLE/PHASES_CPP/DONECallKotlinPerfcompletes full fire/update/callback sweepCallKotlinPerfTestModuleomitted (NDEBUG/ non-DEBUG)