Skip to content

Refactor NotePanel: cache derived tags/links/backlinks and avoid hot-path IO#820

Merged
multiplex55 merged 2 commits intomasterfrom
codex/refactor-notepanel-for-performance-enhancements
Feb 11, 2026
Merged

Refactor NotePanel: cache derived tags/links/backlinks and avoid hot-path IO#820
multiplex55 merged 2 commits intomasterfrom
codex/refactor-notepanel-for-performance-enhancements

Conversation

@multiplex55
Copy link
Copy Markdown
Owner

Motivation

  • Reduce CPU and IO work in the UI hot path by avoiding repeated recomputation of tags, wiki/markdown links, and backlink rows during repaint.
  • Avoid per-keystroke or per-segment file reads (todos/notes) by moving expensive operations off the render path and using cached snapshots.
  • Ensure derived-linking state is refreshed at well-defined semantic points (panel init, successful save, and explicit actions) rather than on every edit event.

Description

  • Added a NoteDerivedView struct and new NotePanel fields (derived: NoteDerivedView, derived_dirty: bool, and a test-only derived_recompute_count) to cache derived metadata such as tags, wiki_links, external_links, backlink rows by category, and a todo_label_map for markdown preprocessing in src/gui/note_panel.rs.
  • Centralized recomputation in NotePanel::refresh_derived(), called on panel init and after successful saves (also used for overwrite/save-as-new paths), and introduced backlink_rows_for_active_tab() to page over precomputed backlink rows instead of recomputing each render.
  • Modified preprocess_note_links to accept an injected todo label map (todo_labels: &HashMap<String, String>) to remove direct load_todos() IO from markdown preprocessing and wired all callers to use self.derived.todo_label_map.
  • Added a cheap read-only snapshot accessor pub fn note_cache_snapshot() -> Vec<Note> in src/plugins/note.rs so UI code can read cached notes without calling load_notes() (disk) during repaint.
  • Mark derived_dirty = true on edit-mode changes and when rendering segments mutate the note, and avoid per-keystroke recomputation; refresh_derived() runs after a successful save() (and related save flows) to update self.note.links and backlink rows.
  • Added unit tests: in src/gui/note_panel.rs tests for derived reuse across renders, recomputation after save() and note.links update, backlink invalidation when slug/targets change, and preprocess_note_links using an injected todo map; in src/plugins/note.rs tests for note_cache_snapshot read-only copy semantics and that it reflects refresh_cache() updates.

Testing

  • Ran cargo fmt --all successfully to format changes.
  • Attempted to run the note_panel tests with cargo test, but the environment Rust toolchain is older than required by a transitive dependency (error: rustc 1.87.0 vs time requiring >=1.88.0), so the test suite could not be executed here.
  • New unit tests were added to src/gui/note_panel.rs and src/plugins/note.rs (see PR diffs) and should pass on a compatible toolchain when run (cargo test).

Codex Task

@multiplex55 multiplex55 merged commit aee41c4 into master Feb 11, 2026
1 check passed
@multiplex55 multiplex55 deleted the codex/refactor-notepanel-for-performance-enhancements branch February 11, 2026 22:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant