SuperchargedReact.Net icon indicating copy to clipboard operation
SuperchargedReact.Net copied to clipboard

Some feedback

Open andersekdahl opened this issue 10 years ago • 1 comments

Hi! This is mostly directed to @PeteDuncanson. We had a discussion over at https://github.com/reactjs/React.NET/issues/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!

andersekdahl avatar Dec 09 '15 13:12 andersekdahl

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.

For what it's worth, V8Runtime pooling might be a nice feature to add to JSPool (in addition to supporting pooling via JavaScriptEngineSwitcher) :)

Daniel15 avatar Dec 09 '15 18:12 Daniel15