Reduce the number of syscalls in FileCache::loadMetadata #52435
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Changelog category (leave one):
Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):
Documentation entry for user-facing changes
--
References #52037
A couple changes focused only on the iteration over the folders to check what's empty:
path = it->path(); fs::is_directory(path)
requires a call tonewfstatat
/stat
. We avoid this syscall by using the information already present in the iterator.fs::is_empty(path)
adds another syscall in order to check the type of path. As we know per the previous condition that it is a directory we can also avoid that syscall to get the type. To do that, we simply build a directory iterator with the path and see if it's empty.cc @kssenii
The impact is hard to measure since it depends on what's in cache and what isn't and the rest of the operations that I haven't measured.
In a synthetic benchmark, with 1000 folders and each one of them 1000 subfolders with 1 file in each, and everything in kernel/disk cache, the iteration time and checks for emptiness go from 4039 ms to 3150 ms in my machine.
Before (4039 ms):
After (3150 ms):
cc @kssenii