Switch to therubyracer and general questions about what JS engine
justin808 opened this issue · 2 comments
- I curious as to the purpose of eval vs. compile methods in the execJS?
- Any advice on what's going the be best performance for rendering react components server side?
- Here's how another project is doing this without webpack: https://github.com/reactjs/react-rails/tree/master/lib/react/server_rendering Anything right or wrong about what they are doing? Here's the docs on that: https://github.com/reactjs/react-rails#server-rendering
Here's a discussion on performance: reactjs/react-rails#290
Summary of performance advice from react-rails:
Recommends: https://github.com/cowboyd/therubyracer
On MRI, use therubyracer for the best performance (see discussion)
On MRI, you'll get a deadlock with pool_size > 1
If you're using JRuby, you can increase pool_size to have real multi-threaded rendering.
- I curious as to the purpose of eval vs. compile methods in the execJS?
They basically the same thing, eval
will unbox the result and convert into ruby values.
https://github.com/rails/execjs/blob/master/lib%2Fexecjs%2Fruntime.rb#L38-L44
https://github.com/rails/execjs/blob/master/lib%2Fexecjs%2Fruby_racer_runtime.rb#L13
https://github.com/rails/execjs/blob/master/lib%2Fexecjs%2Fruby_racer_runtime.rb#L34
- Any advice on what's going the be best performance for rendering react components server side?
I'm not sure, but we definitely doesn't want to instantiate engine every render and request. Yes, execjs
is just universal wrapper for V8
javascript engine, it will auto-detect to select the best one. And here is the order https://github.com/rails/execjs/blob/master/lib%2Fexecjs%2Fruntimes.rb#L77