Skip to content
Mostafa Ahangarha edited this page Oct 4, 2023 · 2 revisions

Based on discussions at #773 and #828

From https://reactjs.org/docs/perf.html

As of React 16, react-addons-perf is not supported. Please use your browser’s profiling tools to get insight into which components re-render.

React-Rails 2.3.x was the last version on React 15 that has react-addons-perf

How to measure

How to test Client Performance

You can use standard browser tools: Chrome Lighthouse Audit

The most interesting statistics to measure are "Perceptual Speed" and "First Interactive", they show how soon someone could see something, and how soon it actually finished loading most of the page.

Run the audit until the numbers roughly stabilize, 3 runs is enough for most meaningful changes.

How to test Server Performance

Wrap specific components using the Rails view-helper in a call to benchmark

<% benchmark 'Root of SPA' do %>
  <%= render_component "WholePageContainer", @large_data_blob %>
<% end %>

If you want to measure all components, you may want to wrap the render_component view-helper itself.

def render_component name, props, prerender
  benchmark("Component #{name}") do
    react_component name, props, prerender: prerender
  end
end

How use instrumentation for Server Performance monitoring

If you're using a tool like Scout, Appsignal, Skylight, NewRelic or others, you may want longer term instrumentation. http://guides.rubyonrails.org/active_support_instrumentation.html

This project gives some direction if you wish to implement this yourself. https://github.com/pboling/react-rails-benchmark_renderer

Client only vs Server + Client performance

Thanks to @arnoldclark for stats and dev time provided.

TLDR: Server-side rendering + Hydrate is faster perceived and first interactive than any other option.

Rendering Serverside + React.Render (React_UJS 2.4.0)

  • 4.0s Interactive
  • 2.3s Perceived
screen shot 2017-11-03 at 20 09 09

Rendering Clientside

  • 3.0s Interactive
  • 2.7s Perceived
screen shot 2017-11-03 at 20 08 15

Rendering Serverside + React.Hydrate (React_UJS 2.4.1+)

  • 2.7s Interactive
  • 2.4s Perceived
screen shot 2017-11-03 at 20 41 56