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

Performance: Improve how MB handles local cache #4305

Open
4 tasks done
pikurasa opened this issue Jan 24, 2025 · 15 comments · May be fixed by #4331
Open
4 tasks done

Performance: Improve how MB handles local cache #4305

pikurasa opened this issue Jan 24, 2025 · 15 comments · May be fixed by #4331

Comments

@pikurasa
Copy link
Collaborator

Description

Every time a user creates a new project, it -- a JSON string -- is stored into the browser's cache.

We've had performance issues upon loading Music Blocks (MB) for a while, and finally determined that loading takes longer the more projects a user has stored to their local browser cache.

In order to solve this problem, we need to look into how we handle local data, so that loading time can be improved.

Expected Behavior

We want MB to load as fast as possible. Preferably as fast as it does from a private tab.

How to Reproduce

One way you can test this is:

  • Create a bunch of projects (or load them, either from the Planet or from the Examples folder), and reload MB
  • Compare loading time against opening MB in a private tab (e.g. Incognito Mode); the loading time when in a private tab will be much quicker than from a tab where local cache is being read.

Console log Errors:

I'm not really sure what logs may be related to this issue. It would be helpful if someone with experience in performance could look into this.

Environment:

  • Operating System: All
  • Browser (if applicable): All
  • Version of Software/Project: All

Note: Faster computers, especially ones with decent GPUs, in my testing, are less noticeably effected by this issue because the overall loading time is faster in either case. If you test on a faster computer, you should also try on a slower machine as well. And, in any case, always make sure to compare against a session that has many projects loaded (see above).

Checklist

  • I have read and followed the project's code of conduct.
  • I have searched for similar issues before creating this one.
  • I have provided all the necessary information to understand and reproduce the issue.
  • I am willing to contribute to the resolution of this issue.

Thank you for contributing to our project! We appreciate your help in improving it.

📚 See contributing instructions.

🙋🏾🙋🏼 Questions: Community Matrix Server.

@Commanderk3
Copy link
Contributor

Commanderk3 commented Jan 24, 2025

@pikurasa We can use APIs like IndexedDB or Dexie. js

@pikurasa
Copy link
Collaborator Author

@pikurasa We can use APIs like IndexedDB orDexie. js

Please tell us more about those options.

@Commanderk3
Copy link
Contributor

I am researching on this. Till now what I have learned is that localStorage can't handle large amounts of data. This could be the reason for being slow.
IndexedDB on other hand is relatively faster when it comes to handle large data.
I will let you know once I find a optimal solution.

@manasbhalerao23
Copy link

@pikurasa we can also use origin private file system (OPFS) which is a highly optimal solution to this

@FirePheonix
Copy link
Contributor

FirePheonix commented Jan 25, 2025

Hey @Commanderk3 , I think we already ARE using indexedDB.
You can view it your Applications tab by pressing CTRL + SHIFT + i on windows OS.

Image

I think the issue here is that the website is currently loading every single one of my projects fully from the database into memory, even if it only shows one project on the screen.
So when we have multiple projects, it LOADS EVERY SINGLE of them into the memory, causing this performance issue.

AND as mentioned by @pikurasa sir:
"Faster computers, especially ones with decent GPUs, in my testing, are less noticeably effected by this issue because the overall loading time is faster in either case."
In case of faster computers, we already have that much memory so it doesn't cause the issue.

A solution to this is implementing lazy loading into ProjectStorage.js . By doing this we ONLY allow meta data, like Name, data, image of project saved and NOT the entire DATA OF PROJECT itself.

I might actually be wrong with this, can you review this comment? I'm looking into it's implementation.

@Commanderk3
Copy link
Contributor

Commanderk3 commented Jan 25, 2025

@FirePheonix, what you said is correct. It loads more than one project. All these projects are shown in "My Projects" on the planet page.

Image

@apsinghdev
Copy link
Contributor

apsinghdev commented Jan 28, 2025

@pikurasa @walterbender I guess combining project suppression for larger projects with lazy loading and archiving older projects in localStorage would make it comparatively faster. Additionally, moving from localStorage to IndexedDB would require us to estimate how much storage is typically needed to run Music Blocks in the browser. I am working on it. will share more details on this.

@Commanderk3
Copy link
Contributor

@apsinghdev We are not using IndexedDB right? But dev tools show MB is using IndexedDB.

@apsinghdev
Copy link
Contributor

@Commanderk3 At some places we use indexedDB but in most instances, we use local storage.

@Aryan4884
Copy link

@apsinghdev why cant we totally switch to IndexedDB in place of local storage?

@apsinghdev
Copy link
Contributor

@apsinghdev why cant we totally switch to IndexedDB in place of local storage?

First we have to know how much storage we need for faster experience in MB. If localstorage provides enough of that, we don't need to switch. If localstorage is not enough, we should.

@pikurasa
Copy link
Collaborator Author

One observation I have is that it seems to take (considerably) longer to run MB from the web than it does to run it locally.

Of course, it takes some time to download all the files from the web. However, I suspect that something else is compounding the issue. It may be worth also looking into the order that things are loaded to see if there is some sort of race condition or other sort of inefficiency.

@apsinghdev
Copy link
Contributor

apsinghdev commented Jan 30, 2025

@pikurasa, I ran a bunch of tests using some tools to check the performance and learned that the real culprit is not the project storage but the way we make HTTP requests and fetch initial CSS and JavaScript.

Image Image

The current fully loaded time of Music Blocks is 15.9 sec. It's not in the optimal range. It should be cut by at least 50%. Probably, I'll do that by next week.

@Commanderk3
Copy link
Contributor

@apsinghdev That might be true. Because when I consoled out the time taken for retrieving data from local storage it only showed a few seconds (less than 3 s). I didn't give much thought to this because my device is powerful.

@apsinghdev
Copy link
Contributor

@apsinghdev That might be true. Because when I consoled out the time taken for retrieving data from local storage it only showed a few seconds (less than 3 s). I didn't give much thought to this because my device is powerful.

IMO, console statements aren't very effective when calculating the time. I tried it too but didn't get accurate results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants