Skip to content
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

Improve 4 second load time #440

Open
LudwikJaniuk opened this issue Mar 29, 2024 · 5 comments
Open

Improve 4 second load time #440

LudwikJaniuk opened this issue Mar 29, 2024 · 5 comments
Labels
not ready This is not ready to be implemented. Do not work on this yet! question Further information is requested

Comments

@LudwikJaniuk
Copy link
Collaborator

We get this when we run npm run dev:

Warning: data for page "/[dataset]/[dataView]" (path "/utslappen/karta") is 2.65 MB which exceeds the threshold of 128 kB, this amount of data can reduce performance.

I am guessing this has to do with the map data. More info is here: https://nextjs.org/docs/messages/large-page-data

But is it so bad? I ran a speedtest which does point out we are suffering from ~4 second load times. This can make someone lose interest if they are on the phone.

So it would be useful to investigate if there are things we could change to improve the load time. The "large page data" issue next.js points out is a good place to start, but we need to measure before/after to verify if that makes a difference, or if we need to look at other stuff as well.

@LudwikJaniuk LudwikJaniuk changed the title Improve load time Improve 4 second load time Mar 29, 2024
@Greenheart
Copy link
Collaborator

Greenheart commented Apr 24, 2024

Ideally we should only load the required dataset for the requested route, instead of responding with all datasets. This is the obvious first step that would greatly improve performance.

For example, if /koldioxidbudgetarna/karta is requested, we should only respond with the required data to render koldioxidbudgetarna.

Other optimizations that could reduce the payload size further (with more work required):

The returned JSON data has many long key names that are used in almost every object. If we reduced the key length, we reduce the amount of data transferred by approximately 10%

We could also consider if we want to have as many decimal points for numbers. For electricCarChangeYearly for example, we send up to 18 decimal points, but only render 1 decimal point in the UI. Why not return the rounded data directly from the server? This could likely save quite a bit of data.

This also goes for all floating point numbers, for emission reductions and more. If exact sorting is important, we could do that on the server side when preparing the dataset. Or even better, pre-process the data in Python so we have both a raw dataset and an optimized version for usage on the website.

To solve potential inconsistencies, we will always be able to provide a raw dataset if anyone asks for it. But the website only cares about the actual data to display. Better to make the raw data available via a JSON download, separately from the Next.js page data.

@LudwikJaniuk
Copy link
Collaborator Author

Good ideas @Greenheart.

@elvbom elvbom added help wanted Extra attention is needed ready This is ready to be implemented labels May 8, 2024
@mathiasb
Copy link
Contributor

mathiasb commented May 8, 2024

Could be possible to create a more consumtion friendly version of the file with a small Transformation script standalone to begin with.

@N-Asadnajafi
Copy link
Contributor

I picked up this task @LudwikJaniuk . It seems there is still room for improvement. As a good practice in Front, I will take advantage of Redux and will separate the logic from the rest of the app. By minimizing unnecessary re-renders, the performance will improve significantly. And as a result we have faster load times and smoother interactions. Overall we will have a better user experience.

@LudwikJaniuk
Copy link
Collaborator Author

LudwikJaniuk commented May 17, 2024

Sounds good and good luck! Please communicate with @Greenheart as you go along to ensure what you're working on is in line with other ongoing work.

@elvbom elvbom added question Further information is requested not ready This is not ready to be implemented. Do not work on this yet! and removed help wanted Extra attention is needed ready This is ready to be implemented labels May 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
not ready This is not ready to be implemented. Do not work on this yet! question Further information is requested
Projects
Status: Ready
Development

No branches or pull requests

5 participants