Live data from Hacker News

The Performance Cost of Server Side Rendered React on Node.js

malloc.fi

21–30 of 134 posts

Re: The Performance Cost of Server Side Rendered React on Node.js

#21

So I thought the entire point of SSR was to speed up initial page load - if you pre-render all the static parts of the page, including what happens after routing, but before any API calls, so that your webserver can cache that static HTML for that route and serve it up. What this means is that the user immediately sees much more of a rendered HTML page, rather than seeing a blank page for 2 seconds and having to wait…

No, it was to improve SEO and other clients without JS

Re: The Performance Cost of Server Side Rendered React on Node.js

#22
post #8

Earlier quoted context omitted.

They do, but the load will be spread among clients. The issue here is the load on the server.

I guess it depends on which direction you're coming from. From a traditional server side point of view, you're reducing the server work to just that first page load and making the client do the rest.

True. But making all server-side renders really efficient and fast is an option, too. http://nathanmlong.com/2016/11/elixir-and-io-lists-part-2-io...

Re: The Performance Cost of Server Side Rendered React on Node.js

#23
post #17
post #13

Earlier quoted context omitted.

They include a comparison with using ES6 Template literals (native JavaScript string interpolation), and saw 10x increase over React. The native string interpolation actually came out just behind serving straight static files. JavaScript CPU performance is actually quite high among interpreted languages. So to answer your question more specifically, no I don't think it is clear. What this is specifically isolating as…

Does anyone actually use vanilla JavaScript string literals for all their backend rendering?

There's the lit-html[1] project, which is still fairly new.

It uses tagged template literals to render to the DOM, so on the server side it could fall back to vanilla string interpolation.

[1]: https://github.com/PolymerLabs/lit-html

Re: The Performance Cost of Server Side Rendered React on Node.js

#24
post #10
post #2

I thought the idea was to render it server side just once, then have the client take over for all future requests? In which case it's 10x slow for the first page load, but all future requests are just hitting API endpoints and can be fairly fast?

Correct, except that initial app load time for un-cookied users with cold browser caches is a critical metric, since it largely determines whether they'll keep using your app. Fortunately, those are the scenarios where server-side caching can have a decent benefit, since you're essentially rendering the same view to all such users.

If all first time users see the same thing, why not serve a precompiled static html that then gets taken over by React.

Isn’t that the whole point?

Re: The Performance Cost of Server Side Rendered React on Node.js

#25
post #19
post #17

Earlier quoted context omitted.

Does anyone actually use vanilla JavaScript string literals for all their backend rendering?

I do this. It’s surprisingly effective, both in actual performance and developer productivity. The one area where it is useless however is for mutating DOM. It’s easy enough to create DOM using template strings, but if you say need to render something and then mutate it later on in you render function, it becomes terrible since you either have to do tricky string manipulation, actually create the DOM and use methods…

I have no personal experience with it, but Google's been toying with this project: https://github.com/PolymerLabs/lit-html

Might help with some of those pain points

Re: The Performance Cost of Server Side Rendered React on Node.js

#26
post #17
post #13

Earlier quoted context omitted.

They include a comparison with using ES6 Template literals (native JavaScript string interpolation), and saw 10x increase over React. The native string interpolation actually came out just behind serving straight static files. JavaScript CPU performance is actually quite high among interpreted languages. So to answer your question more specifically, no I don't think it is clear. What this is specifically isolating as…

Does anyone actually use vanilla JavaScript string literals for all their backend rendering?

I use a combination of both template string literals and React SSR streaming.

https://github.com/styfle/react-server-example-tsx/blob/4586...

Re: The Performance Cost of Server Side Rendered React on Node.js

#28
post #24
post #10

Earlier quoted context omitted.

Correct, except that initial app load time for un-cookied users with cold browser caches is a critical metric, since it largely determines whether they'll keep using your app. Fortunately, those are the scenarios where server-side caching can have a decent benefit, since you're essentially rendering the same view to all such users.

If all first time users see the same thing, why not serve a precompiled static html that then gets taken over by React. Isn’t that the whole point?

So very much this. Particularly if you dont have enough context to be personalized, pre-compiled popular segments are a reasonable approach.

Re: The Performance Cost of Server Side Rendered React on Node.js

#29
post #21

So I thought the entire point of SSR was to speed up initial page load - if you pre-render all the static parts of the page, including what happens after routing, but before any API calls, so that your webserver can cache that static HTML for that route and serve it up. What this means is that the user immediately sees much more of a rendered HTML page, rather than seeing a blank page for 2 seconds and having to wait…

No, it was to improve SEO and other clients without JS

That's part of it, but getting viewable content to the user as soon as possible is just as big. Without SSR, the user has to wait for the JS to download, parse, and execute before they see anything on the page.

Re: The Performance Cost of Server Side Rendered React on Node.js

#30
post #17
post #13

Earlier quoted context omitted.

They include a comparison with using ES6 Template literals (native JavaScript string interpolation), and saw 10x increase over React. The native string interpolation actually came out just behind serving straight static files. JavaScript CPU performance is actually quite high among interpreted languages. So to answer your question more specifically, no I don't think it is clear. What this is specifically isolating as…

Does anyone actually use vanilla JavaScript string literals for all their backend rendering?

Couldn't tell you, but it's not really relevant. The post I'm replying to says that it should come as no surprise that NodeJS template rendering is slow, and I just meant to point out that the article is quite specifically isolating ReactJS rendering as slow, and has nothing to do with NodeJS or JS at all.
Post reply on HN