react-native icon indicating copy to clipboard operation
react-native copied to clipboard

Why not use JSExport to implement the bridge?

Open cxfeng1-zz opened this issue 11 years ago • 3 comments

I found that the js-to-native bridge is implemented by calling BatchedBridge.callFunctionReturnFlushedQueue from native continuously, thus "flush" the ModuleID,MethodId,CallbackID and arguments to native.

Does this mean eating up a lot of battery life?

Why not use JavascriptCore's JSExport protocol to implement the bridge ?

Thanks :)

cxfeng1-zz avatar Apr 01 '15 09:04 cxfeng1-zz

/cc @jordwalke @sahrens

a2 avatar Apr 01 '15 10:04 a2

I observed memory corruption with JSExport on iOS7. It was very difficult to reproduce, but when I finally reproduced it I rewrote it in terms of serialized strings. If anything, we should eventually just use the raw JSC c API, but IIRC flushing/serializing is not the bottleneck (if you see otherwise, please let us know). In fact, in one benchmark @frantic and I found that just copying the entire data at once was faster than using micro-hooks to convert each piece of the data using the JSC c API - it might have something to do with crossing the JS/native boundary several times vs. in one batch.

jordwalke avatar Apr 01 '15 20:04 jordwalke

Now using JSC C api as per #1037

brentvatne avatar May 31 '15 16:05 brentvatne