-
Notifications
You must be signed in to change notification settings - Fork 755
Server side rendering performance issues #156
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Something to note from upstream in React world... during the QA at React.js Conf, it was mentioned that server-side rendering, while awesome, was not one of the chief design goals of React. It doesn't look like the video of the QA session is up yet. Just something to note as we consider performance when it's wrapped in Ruby. |
Good to know. It's not a big issue, just wanted to see if anyone else was noticing similar performance issues or if I had a config issue somewhere. I'll close this out. |
In case anyone wonders, server side generated component can be cached Not sure yet if this is very helpful, as properties passed may change |
@oelmekki Could you provide a code example of how your handle caching the |
Hi @ssaunier , Nothing fancy, I just use standard russian doll caching: - cache my_cache_key do
= react_component 'MyComponent', my_props, prerender: true In my last project, I've succeeded in caching def custom_cache_key( prefix, resource, collection: false )
if current_user
prefix += '-logged'
prefix += '-admin' if current_user.is_admin?
end
if collection
"#{prefix}-#{resource.maximum( :updated_at ).to_i}"
else
"#{prefix}-#{resource.cache_key}"
end
end I can then use it like this (the presenter class returns a hash for properties): - cache custom_cache_key( 'product-list-hot', @products, collection: true ) do
= react_component 'ProductList', ProductPresenter.collection( @products, self ).to_h, prerender: true The thing is, properties can be different for pretty much every user, I've avoided adding user specific info in my components. Should I need |
@oelmekki Thanks for the quick reply, great material! 👍 |
You're welcome :) Oh, a last thing: given the composable nature of react, you have to For that reason, your caching should be short living, or you'll have I use redis, so I've set this in cache configuration: config.cache_store = :redis_store, redis_url, { expires_in: 90.minutes } |
FYI: https://github.com/cowboyd/therubyracer/tree/upgrade-to-v8-4.5 When this comes out, that will enable multi-threaded rendering, hopefully. |
I have an application that is rendering ~5000 sub-components. When prerendering using the ExecJS prerender engine, this takes about 1.5 seconds. Without prerendering, it takes about 700ms, and doing a hybrid approach of rendering using Rails templates and then overwriting with a React.render() takes about 600ms.
Profiling the ExecJS server side rendering, I get the following:
Switching the JSON renderer to Oj improves performance slightly and increases the percentage of the V8 script call.
Curious if anyone else experiences the same thing, or maybe there's an issue with my rubyracer's libv8 compilation? It doesn't make much sense to me that the JS execution would be consistently so much slower.
The text was updated successfully, but these errors were encountered: