Giter Club home page Giter Club logo

Comments (4)

jackyef avatar jackyef commented on May 24, 2024

This is interesting. I did not expect this to double the latency.

I will try to create a simple reproduction and profile them to see what might be going on, and what can be improved.

EDIT (Explanation add at #52 (comment))
Actually, it makes sense. We are doing a prepass before doing the actual render, so that alone should almost double the processing time.

For the adding useData() hook, I suspect it might be affected by the API latency, data size, and the data processing.

from react-isomorphic-data.

chris-hinds avatar chris-hinds commented on May 24, 2024

Thanks @jackyef if you do spot anything obvious please let me know, we are happy to contribute fixes/improvements to this library.

from react-isomorphic-data.

jackyef avatar jackyef commented on May 24, 2024

@hindsc52 For the one with 1 useData() hook, what is the latency of the endpoint you are fetching from? Could it be around ~200ms?

from react-isomorphic-data.

jackyef avatar jackyef commented on May 24, 2024

So, after doing some profiling, I see that the task that takes the longest is code from react-ssr-prepass. This is basically walking through the app tree and resolve thrown promises (Suspense) as it sees them.

image
image

As shown in the screenshots above, the longest 2 block of tasks (other than react's own renderToString and renderDOM) is from react-isomorphic-data line 168. Which contains the code from react-ssr-prepass.

Since the alternative is to call renderToString multiple times, I tried to do a simple benchmark.

┌─────────┬──────────────────────────┬───────────────────┬───────┐
│ (index) │           name           │      average      │ stdev │
├─────────┼──────────────────────────┼───────────────────┼───────┤
│    0    │ 'react-ssr-with-prepass' │ 150.1085802333333 │ 22.79 │
│    1    │   'react-ssr-isodata'    │ 156.2910870333333 │ 19.12 │
│    2    │   'react-ssr-3-times'    │ 210.0336295333333 │ 5.55  │
└─────────┴──────────────────────────┴───────────────────┴───────┘

Explanation:

  1. react-ssr-with-prepass is doing await prepass(app) before doing renderToString(app);
  2. react-ssr-isodata is doing await renderToStringWithData(app), without any useData hooks in the app.
  3. react-ssr-3-times is just calling renderToString(app) 3 times.

So, react-ssr-with-prepass is the fastest out of the 3. react-ssr-isodata is slightly slower, which is expected because it uses prepass internally. With more hooks, the number could be worse depending on the API latency, data size, and how the data is processed.

react-ssr-3-times is done to simulate rendering the App 3 times to collect all data, but in real world cases, this could be more, with the minimum being 2.

Note: this benchmark renders 64472 divs recursively, which is quite extreme and does not usually happen in real world app. Nevertheless, we can take some insights from it.

You can run the benchmark here: https://github.com/jackyef/react-isomorphic-data-benchmark

Summary

I would say if your app previously do fetching before calling renderToString 1 time, you will surely see performance degradation. I guess that would be the cost of having the ability to declare data requirement in the components + automatic handling of nested and conditional data requirement.

from react-isomorphic-data.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.