Hi!
This is mostly directed to @PeteDuncanson. We had a discussion over at reactjs/React.NET#134 about which engine to use to server render React.
After first playing with Edge.js to do it, I've taken the code from SupercharedReact.Net and tried it out. Works great, and I'd like to give some feedback:
- The project currently assumes that you use React Router (which is awesome, but we're not using it). It also assumes that the two globals
React and Router exists. We import React inside of our bundle, and instead just export a function that is called from the C# side to get the HTML string with props passed in.
- The project currently only uses one
V8Runtime instance to handle all requests. Which might work for light/medium load but it can quickly become a bottleneck. I've created a pool of V8Runtimes with inspiration taken from JSPool by @Daniel15 and from ClearScript.Manager. So requests get responded to by multiple V8 instances. We're debating here if we should skip server rendering if the pool is busy or if we should block and wait for an instance. Or perhaps use async/await and create a queue of work that the pool can process.
- I noticed that creating one
V8ScriptEngine once at startup instead of doing it for every request gave a speedup of about 100ms per req. Not sure why you need to create a script engine per request, am I missing something?
- Our bundle doesn't create any globals, so I removed the cleanup where it goes through globals and deletes them. Instead I only run V8 garbage collection in the cleanup. I suspect that I'll tweak when to actually run the garbage collection.
Thanks a lot for making this open source!
Hi!
This is mostly directed to @PeteDuncanson. We had a discussion over at reactjs/React.NET#134 about which engine to use to server render React.
After first playing with Edge.js to do it, I've taken the code from SupercharedReact.Net and tried it out. Works great, and I'd like to give some feedback:
ReactandRouterexists. We import React inside of our bundle, and instead just export a function that is called from the C# side to get the HTML string with props passed in.V8Runtimeinstance to handle all requests. Which might work for light/medium load but it can quickly become a bottleneck. I've created a pool ofV8Runtimes with inspiration taken from JSPool by @Daniel15 and from ClearScript.Manager. So requests get responded to by multiple V8 instances. We're debating here if we should skip server rendering if the pool is busy or if we should block and wait for an instance. Or perhaps use async/await and create a queue of work that the pool can process.V8ScriptEngineonce at startup instead of doing it for every request gave a speedup of about 100ms per req. Not sure why you need to create a script engine per request, am I missing something?Thanks a lot for making this open source!