What is JSI?
It's an interface which enables JavaScript (whether it's JSC or Hermes) to communicate with native (C++) and vice versa.
Hence using this we can eliminate the bridge. Instead we can take the following route.
Android : Java <-> JNI <-> JSI <-> Javascript.
iOS : ObjC <-> JSI <-> Javascript.
Benchmarking JSI
- RN version: 0.63.4
- NDK Version: 22.0.x
- CMake Version: 3.10.x
- Test Device : Samsung S10
Operations
- Get String from KV store:
- Android Shared Prefs over JSI
- Async Storage
- Android Shared Pref over Bridge
- Retrieve a Java String
- JSI
- Bridge
- Retrieve a Java Object
- JSI
- Bridge
- Query 100 Rows from Table
- JSI
- Bridge
Results:
-
Get a JSON string of 212148 characters from KV Store
- JSI (Async - Spawn a thread on Java)= ~ 5 MS (Min 2 MS - Max 8 MS)
- JSI (Sync)= ~ 2 MS (Min 1 MS - Max 3 MS)
- Async Storage = ~ 22 MS (Min 12 - Max 35 MS))
- Bridge = ~ 14 MS (Min 8 MS - Max 20 MS)
-
Get a Java String to JS through JNI and JSI
- JSI = <= 1 MS (Min 0 MS - Max 1 MS)
- Bridge = ~ 8 MS (Min 6 MS - Max 15 MS)
-
Get a Java Object (Two String properties) to JS through JNI and JSI
- JSI = <= 1 MS (Min 0 MS - Max 1 MS)
- Bridge = ~ 14 MS (Min 10 MS - Max 18 MS)
-
Query 100 rows of students in a class table - (Query time is ~ 5-10 MS)
- JSI = ~ 15 MS (Min 10 MS - Max 20 MS ) - Cursor iteration on Java.
- JSI = ~ 22 MS (Min 15 MS - Max 30 MS) - Cursor iteration on JS.
- Bridge = ~ 45 MS (Min 30 MS - Max 60 MS)
License
MIT