Prune excluded directories from the index walk#741
Conversation
Exclude globs were only matched against files, so an excluded directory was still traversed and filtered file by file. On notebooks that contain large ignored trees (e.g. asset or vendored directories) this made indexing needlessly slow. shouldIgnorePath now takes an isDir flag: for a directory it skips the note-extension check and matches the exclude globs (supporting both the "foo" and "foo/**" forms), and Walk prunes a matching directory with filepath.SkipDir instead of descending into it. File-only globs keep their previous behaviour. Adds a unit test asserting the walker never queries paths inside a pruned directory, plus a tesh end-to-end test. Closes zk-org#728
|
Other than those two details, looks good. |
|
@ehsash Added one change to docs. The inner workings of how a walk is happening doesn't need to be explained in user facing documentation. Also, it was written that a directory can be excluded with Shouldn't it be |
If you have a file named If you have a directory called |
|
Ah yep, of course. That makes sense. @ehsash Not sure if you've seen, but the tesh case is failing. Should I look at it, or you good to look at it? |
I'll have a look tomorrow afternoon and take the other remarks in account. You'll have a new commit in the PR that fixes this :-) |
Summary
Fixes #728.
Exclude globs are currently only matched against files, so an excluded
directory is still walked and filtered file by file. On notebooks that contain
large ignored trees (asset directories, vendored repos, ...) the indexer spends
most of its time
lstat-ing files it then discards, which makes indexing — andevery
zkinvocation that reindexes — slow.This makes the walker prune a directory matched by an exclude glob, with
filepath.SkipDir, instead of descending into it.Changes
shouldIgnorePathnow takes anisDir bool:.mdextension) andis matched against the exclude globs alone;
fooand the subtreefoo/**forms prune the directory.paths.Walkprunes a directory rejected byshouldIgnorePathwithfilepath.SkipDir(the notebook root is never pruned).*.png,dir/*) match exactly asbefore; only directory matches now prune.
Tests
internal/util/paths/walk_test.go: a new test asserts the walker never evenqueries paths inside a pruned directory — proving the subtree is skipped,
not filtered file by file.
tests/issue-728.tesh: end-to-end test covering both thefooandfoo/**forms.
gofmtclean;go test ./...passes.Impact
On a ~12k-note notebook sitting next to a large (40+ GB, ~170k-entry) asset
directory, excluding that directory takes indexing from re-walking every asset
entry on each index to skipping the tree entirely.