discussions-and-proposals icon indicating copy to clipboard operation
discussions-and-proposals copied to clipboard

Create JS 'compiler'(not interpreter) like flutter.

Open sarath263 opened this issue 5 years ago • 8 comments

Introduction

What about serving React native with its own js compiler which compiles jsbundle to bytecode and then into executable binary. Which is same like Flutter came with its own "Game Engine" they call.

Details

Is it possible for react native team to create a compiler, using JIT in v8 engine such that jsbundle transformed to executable binary and this binary will talk to native platforms using the react bridge.

To do

React bridge might need to be rewritten in a compiled language/compiled as a binary executable.

Discussion points

Yes, I am asking for a real JS 'compiler' instead of 'interpreter'. Just like flutter.

It will require experts on v8 engine to create something like the same.

Takeaways

No dependency on web engines on different platforms React Native will serve with js runtime engine.(Full js compiler like a game engine)

sarath263 avatar Sep 09 '20 06:09 sarath263

Since JSI and Turbomodules are under development this Isn't really needed, you can have your own native code written in C++ and it's relative instructions and communicate back to javascript via JSI.

0xC0A1 avatar Sep 16 '20 20:09 0xC0A1

I have a lot of faith in Turbomodules and JSI so we can eventually see less "Native component" oriented solutions and more "Game Engine | Canvas" solutions for react native.

0xC0A1 avatar Sep 16 '20 20:09 0xC0A1

I have a lot of faith in Turbomodules and JSI so we can eventually see less "Native component" oriented solutions and more "Game Engine | Canvas" solutions for react native.

Thanks for the point, but even if there are Turbomodules, it is again a new architecture to speed up the way Native Modules are initialized and invoked from JavaScript . Will the js interpretation not be again the bottleneck.

sarath263 avatar Sep 17 '20 05:09 sarath263

cc @Kudo I'm sure you have something to say about this :)

kelset avatar Sep 18 '20 10:09 kelset

  1. Hermes did support what you mentioned - the bytecode bundle. However, it is in Hermes bytecode format (not in assembly). Flutter, on the other hand, in some situation, the AOT mode supports compiling to assembly. (Ref here, please correct me if I am wrong). Although Dart could be compiled into assembly code, it still needs a Dart runtime during execution.

  2. V8 also support something like the bytecode format, it is called a snapshot and like what Flutter "Application Snapshot" mode. Unfortunately, react-native-v8 does not support startup snapshot yet.

Hopefully if I answered your questions. If not, please feel free to let me know. Thanks @kelset for reminding me to answer this.

Kudo avatar Sep 18 '20 15:09 Kudo

  1. Hermes did support what you mentioned - the bytecode bundle. However, it is in Hermes bytecode format (not in assembly). Flutter, on the other hand, in some situation, the AOT mode supports compiling to assembly. (Ref here, please correct me if I am wrong). Although Dart could be compiled into assembly code, it still needs a Dart runtime during execution.
  2. V8 also support something like the bytecode format, it is called a snapshot and like what Flutter "Application Snapshot" mode. Unfortunately, react-native-v8 does not support startup snapshot yet.

Hopefully if I answered your questions. If not, please feel free to let me know. Thanks @kelset for reminding me to answer this.

That's really a detailed answer.. thanks @Kudo . Can we take it and make as a proposal to create react-native-v8 support for bytecode startup snapshot and to create and serve bytecode snapshot to v8 instead of jsbundle.. I believe it will make RN to perform more than native. Really excited to see it happen.

sarath263 avatar Sep 19 '20 04:09 sarath263

@sarath263 Hermes already supports bytecode startup and it is officially supported JS runtime for react-native. Please take a look first. For react-native-v8, I am sorry that I don't have much time to do this in the mean time.

Kudo avatar Sep 21 '20 08:09 Kudo

Just a question, as @Kudo mentioned

Flutter, on the other hand, in some situation, the AOT mode supports compiling to assembly. (Ref here, please correct me if I am wrong). Although Dart could be compiled into assembly code, it still needs a Dart runtime during execution.

Do react-native-v8 or hermes has any plans to support compiling to assembly just like flutter.

sarath263 avatar Sep 12 '21 17:09 sarath263