Bridge cũ (Legacy):
- Gọi native = serialize args thành JSON → đẩy vào queue async → native deserialize → execute → trả result qua queue ngược lại.
- Async-only, batched mỗi 5–10 ms.
- JS không thể giữ tham chiếu trực tiếp tới object native — chỉ giao tiếp qua module ID + method name.
JSI (JavaScript Interface): C++ API exposed bởi engine (Hermes/JSC):
// C++ side — đăng ký function lên JS
jsi::Function::createFromHostFunction(runtime, propName, paramCount,
[](Runtime& rt, const Value& thisVal, const Value* args, size_t count) {
return jsi::Value(42)
})// JS side — gọi như function thường, sync
const result = global.myNativeFn() // = 42Khác biệt cốt lõi:
- Sync call: global.x() chạy ngay, return value ngay, không Promise.
- HostObject / HostFunction: native expose object/function trực tiếp lên global JS.
- Không serialize: truyền tham chiếu object qua C++ — Buffer, ArrayBuffer, String chia sẻ memory.
- Hỗ trợ tất cả engine: Hermes, JSC, V8 (custom build) đều implement JSI interface.
Hệ quả thực tế:
- Reanimated 3 chạy worklet trên UI thread, đọc shared value đồng bộ → animation 120fps.
- VisionCamera gửi frame buffer (camera preview) sang JS không serialize.
- Database adapter (WatermelonDB, Op-SQLite) query 1000 row 10× nhanh hơn AsyncStorage.
- TurboModules dùng JSI cho mọi method call.