question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Server rendering is slower with npm react

See original GitHub issue

I ran a few benchmarks on the server (modifying https://github.com/paulshen/react-bench to not use jsdom). The results were surprising, as the browserified react.js was about 30% faster than the npm version, even with NODE_ENV=production.

The performance ranking (test run time) was react.min.js < react.js < NODE_ENV=production node react < node react.

I suspect process.env is not a regular js object but perhaps a getter and thus carries a penalty when you test for "production" !== process.env.NODE_ENV everywhere.

Also the minified version might still perform best of all, as at least some time ago V8 used function source length (including comments) as a heuristic for function complexity / compilation time and thus affecting chances for optimization in some cases, but the effect might be negligible.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Reactions:10
  • Comments:59 (24 by maintainers)

github_iconTop GitHub Comments

9reactions
STRMLcommented, Jan 19, 2016

@mhart Technically you can fix the problem in your own code by doing process.env = JSON.parse(JSON.stringify(process.env)), converting it from a live object that calls getenv down a plain JS object. You’ll get the same performance benefits, with the only downside that any code that was relying on live edits to the env (does anyone really do that?) will fail.

2reactions
STRMLcommented, Mar 8, 2017

Referencing https://github.com/facebook/fbjs/pull/86 which will fix this now that UglifyJS can properly eliminate dev code (even if it references a var that never changes) with its new reduce_vars option, which is a default.

See https://github.com/facebook/fbjs/pull/86#issuecomment-285204734 for more context.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Improve app performance with React server-side rendering
React server -side rendering offers performance benefits vs. client-side rendering. Learn about different React SSR frameworks.
Read more >
My React App is working very slow on LocalHost but it is ...
My React App is working very slow on LocalHost but it is working fine in Live Server. UI Rendering is very slow. What...
Read more >
What to do when your React app feels slow - ITNEXT
React is fast, but for some reason your app feels slow. ... Get a ballpark figure of what's re-rendering too much. React devtools...
Read more >
Server-side rendering 'slow', or am I doing it wrong? : r/reactjs
My first inclination is to get a naive baseline of the type of overhead React rendering will add to my server. To that...
Read more >
Slow page load? Not anymore — The Power of Server Side ...
With modern web frameworks like React, the browser received an empty document with java-script links and then rendering started, thereby the ...
Read more >

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found