Skip to content

[Performance] Reduce filesystem operations in FSAL provider#6072

Merged
nathanlesage merged 9 commits into
Zettlr:developfrom
benniekiss:fsal-descriptors
Dec 27, 2025
Merged

[Performance] Reduce filesystem operations in FSAL provider#6072
nathanlesage merged 9 commits into
Zettlr:developfrom
benniekiss:fsal-descriptors

Conversation

@benniekiss

@benniekiss benniekiss commented Dec 22, 2025

Copy link
Copy Markdown
Collaborator

Description

This PR reduces several file system operations in the FSAL layer to improve performance

Improves and possibly closes #6057 and #6018

Changes

The descriptors load in the reindexFiles method are now cached in a _loadedDescriptors attribute. This dramatically improves performance of the findExact method, which re-computes descriptors for all loaded files on each call. Currently, the findExact method is the only place where _loadedDescriptors is used. This was causing performance issues when a file had several zkn links, and hundreds of files were opened in Zettlr.

So I found that the reindexFiles method does not get called often enough, so when files are added or removed, _loadedDescriptors will quickly become out-of-sync with the actual list of available files. Instead, I re-implemented the findExact logic within the link provider. By still calling getAllLoadedDescriptors, the list of available descriptors is up to date, and it can be reused across function calls, greatly reducing the performance impact.

Several calls to pathExists, isFile, and isDir were removed because lower level functions already handled the check. Instead, they were replaced with try...catch blocks. This also improves performance. In my ~500 file workspace, FSAL indexing currently takes about 450ms, but with this patch, it is about 250ms to reindex.

Additional information

I believe _loadedDescriptors could replace getAllLoadedDescriptors entirely, but I wasn't certain.

I tested this in a folder of about 500 files, and I did not notice an increase in RAM usage.

Tested on: macOS 26

* the store quickly can get out of sync with the actual
* available files
* this allows us to re-use the list of all descriptors
* while still keeping the most up-to-date list. This avoids
* the performance impact of constantly calling
* `getAllLoadedDescriptors` in the FSA `findExact` method
@nathanlesage

Copy link
Copy Markdown
Member

Ahh, totally forgot to comment! I had a look and from the outset it looks like a bunch of decent improvements! I'll merge this as soon as 4.0 is out; with your other PRs and a few things I have on my mind we'll be able to get out a 4.0.1 quickly after, and catch a few bugs we've overlooked for 4.0 too.

@benniekiss

Copy link
Copy Markdown
Collaborator Author

sounds great.

merry xmas eve to you, as well!

* we can access the descriptor's extension,
* so just test whether the query + ext is equal
* to the filename
@nathanlesage

Copy link
Copy Markdown
Member

Oh, yes, Merry Christmas! 🙈

@nathanlesage nathanlesage left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one small refactor, but I appreciate the much lower disk accesses here.

Comment thread source/app/service-providers/links/index.ts Outdated
@nathanlesage

Copy link
Copy Markdown
Member

Looks good! Merci beaucoup!

@nathanlesage nathanlesage merged commit 4748f26 into Zettlr:develop Dec 27, 2025
1 check passed
@benniekiss benniekiss deleted the fsal-descriptors branch December 27, 2025 14:49
benniekiss added a commit to benniekiss/Zettlr that referenced this pull request Dec 28, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[v4.0.0-beta.4] Significant CPU usage when opening document with large number of ZKN links

2 participants