Repository navigation
Conversation
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
|
Update: #1858 adds the short-string optimization and new benchmarks, including cached and uncached JNI environments. The short ASCII sample below is Large and Unicode strings improve here. Short ASCII strings regress, including 17-character strings in both directions and empty strings from JNI to JS. JSON results depend on payload size and direction. Measured on an arm64 Android emulator with Hermes, a Release instrumentation APK, and native All 24 non-timed validation groups passed in all 3 runs. The old path fails exact roundtrips for embedded NUL and lone surrogates, so those rows have no performance ratio. The direct path preserves both. Primitive scalar controls measured about 0.7-1 ns/op, too close to the loop floor for a performance claim.
|
42995d9 to
d2b68dc
Compare
d2b68dc to
22c28bc
Compare
|
I compared cached Three fresh process runs on an ARM64 Android emulator, with all implementations in the same APK. NDK 29, JNI-to-JSI conversion times with a cached JNI environment, including the AnyJSON getter, string conversion, parsing, and handle destruction:
Below 1 means the candidate is slower. Times are medians of per-process median times; ratios are medians of paired batch ratios. An attached thread without fbjni's JNI environment cache showed the same overall result. Adding an ASCII scan/copy before SIMD did not help overall either. The parser matters more than the removed function call here. Hermes's JSON.parse entry point selects its raw ASCII or UTF-16 lexer, which has SIMD scanning. The native UTF-8 entry point selects the streaming UTF-8 lexer. For the 4096-character ASCII string, parsing prebuilt input measured 256 ns through cached JSON.parse versus 4496 ns through the native UTF-8 API. Those supporting measurements exclude JNI and transcoding and run in fixed component order; they are not an additive breakdown of the total timings. Correctness covered 66 inputs per context/run, including every JSON root, NUL, BOM, malformed tails, raw/escaped surrogates, and buffer boundaries. The current path and both SIMD candidates passed all comparisons. SIMD falls back to the complete original UTF-16 text on invalid UTF-16: JSON strings can contain raw lone surrogates, so replacing them would change the value. The separate fbjni A JSI UTF-16 overload backed by Hermes's existing raw UTF-16 parser would avoid the temporary JS string and function call without this UTF-8 round trip. No simdutf dependency or converter change was added. The benchmark sources and results remain outside the repository. |
22c28bc to
b2e8454
Compare
c84a311 to
919d05e
Compare
919d05e to
93351a0
Compare
93351a0 to
639d554
Compare
|
Checked the JNI rules and benchmarked the string assembly alternatives before changing the implementation. The The JS-to-JNI path already passes contiguous UTF-16 straight to Measured in a separate Android API 36 arm64 emulator app,
Concat adopts the first fragment directly and only calls A valid JNI-to-JSI Critical alternative allocated scratch before acquiring, copied, released, then created the JSI string. Scratch allocation is included in timing:
All 285 bit-exact checks passed, including embedded NUL, lone surrogates, and pairs split across synthetic fragments. Raw JNI was used equally for the candidates to isolate assembly costs; this is not an end-to-end Nitro/fbjni benchmark. These are emulator results, not physical-device latency estimates. The results support keeping native buffer assembly for segmented input. They do not establish a general JS-to-JNI vector-to-stack speedup. Short JNI-to-JSI region copying does help here and is already in #1858. No implementation changes were made from this experiment. Benchmark sources and raw samples remain outside the repository. |
639d554 to
0349b0a
Compare
Converts strings directly between JSI and JNI with getStringData and ASCII/UTF-16 copies. Avoids std::string on the direct path and preserves embedded NUL and lone surrogate code units.
Validation: Nitrogen typecheck and full spec generation. Generated output is included.