perf(vault/search): faster file-tree scan + cached notes_list index#51
Draft
kodinkod wants to merge 2 commits into
Draft
perf(vault/search): faster file-tree scan + cached notes_list index#51kodinkod wants to merge 2 commits into
kodinkod wants to merge 2 commits into
Conversation
The sort comparator in read_dir_recursive called Path::is_dir() and file_name() on every comparison, turning a single folder scan into O(n·log n) stat syscalls and string allocations. Resolve each entry's directory-ness and name once up front and sort on the cached values. Behaviour (symlink-following is_dir, dirs-first/alphabetical ordering, manual tree-order) is unchanged.
|
|
notes_list walked the whole vault and read+parsed every .md on every call (quick switcher, wikilink completion, navigation, table cells) just to extract each note's title. On large vaults that is seconds of I/O and parsing per invocation. Add a per-vault metadata index at .mycel/index.db (core/index.rs, separate from the AI index so it works without AI). notes_list now walks the directory and only reads+parses .md files whose mtime changed since the last scan; unchanged notes serve their title from the cache. The cache is self-healing (external edits bump mtime -> re-read) and prunes entries for deleted/moved files. Encrypted .md.age notes are never indexed (title is the stem). If the index fails to open, the command transparently falls back to the original full scan. Opened on vault_open and reset on vault switch, mirroring AI state.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Оптимизации работы с ФС на больших хранилищах. Две независимые правки.
1.
read_dir_recursive— лишниеstatпри сортировке дереваsrc-tauri/src/core/vault.rs. Компаратор сортировки вызывалPath::is_dir()иfile_name()на каждое сравнение → скан папки делал O(n·log n)stat-сисколов и аллокаций вместо O(n). Теперьis_dir/имя вычисляются один раз на запись, сортировка идёт по закэшированным значениям. Поведение (следование симлинкам, «папки сначала → алфавит», ручнойtree-order.json) — без изменений.2.
notes_list— SQLite-индекс заголовков с инвалидацией по mtimenotes_listобходил весь vault и читал+парсил каждый.mdна каждый вызов (быстрый переключатель, автодополнение вики-ссылок, навигация, ячейки таблиц) — только ради заголовка. На больших хранилищах это секунды I/O и парсинга на вызов.core/index.rs— отдельная БД<vault>/.mycel/index.db(независимо от AI-индекса, работает и без AI), таблицаnote_titles(path, mtime, title).notes_listобходит каталог и читает/парсит только.mdс изменившимсяmtime; для остальных берёт заголовок из кэша. Самовосстанавливается (внешние правки → меняется mtime → перечитываем), вычищает записи удалённых/перемещённых файлов..md.ageне индексируются (заголовок = stem, без чтения файла).vault_openи сбрасывается при смене vault (как AI-состояние).Проверка
Установлены GTK/WebKit-зависимости, крейт собран. Юнит-тесты модуля индекса:
Полный
cargo test --lib— без регрессий.Это первый шаг плана по индексации. Следующие шаги (отдельными PR): добавить в индекс
wikilinks→ ускоритьbacklinks_getиgraph_data; затемtags→notes_by_tag.https://claude.ai/code/session_01LVDQPy3hFcioM1EJBrreRt