Astrabit-ST / Luminol

An RPG Maker XP-VX Ace rewrite, written in Rust with love 💕
https://luminol.dev/
GNU General Public License v3.0
101 stars 12 forks source link

Lazy path cache #90

Closed white-axe closed 8 months ago

white-axe commented 8 months ago

Description This changes the path cache to only cache paths when they are accessed instead of performing a full recursive directory search as soon as a project is loaded.

Making the path cache lazy in this way is beneficial mostly to web builds but also just to people with really slow storage, because it prevents the path cache from recursively searching directories that are never used, such as the .git directory in projects that use Git for version control, or the Audio directory if the sound test window is never used. This also prevents errors if the user doesn't have permission to access some of the files in the project directory that aren't used by Luminol.

The project loading should be significantly faster in Firefox in #88 when combined with this pull request and should also be a little faster in Chromium.

The lazy path cache is implemented by, whenever the user wants to access a path, first finding the longest path in the cache that is a prefix of the desired path and then searching the filesystem for and caching the missing suffix if applicable. Since the hash table previously used by the path cache doesn't efficiently support this longest common prefix operation, I've replaced the hash table with a trie. The trie doesn't use hashing at all, so it should also be faster than the hash table.

Testing Try loading and editing a bunch of projects as a general stress test of this new path cache and make sure there are no errors that weren't there before. You can check the Filesystem Debug window under the Debug menu in the top bar to make sure that the caching is actually lazy.

Checklist