Skip to content

perf(mail): index badge counts by account in sidebar projection - #145

Open
alfirus wants to merge 1 commit into
flectar:mainfrom
alfirus:perf/sidebar-badge-index
Open

alfirus wants to merge 1 commit into
flectar:mainfrom
alfirus:perf/sidebar-badge-index

Conversation

@alfirus

@alfirus alfirus commented Oct 27, 2026

Copy link
Copy Markdown

Summary

mailbox_entries_with_counts (src/mail.rs) ran a linear scan over the per-account badge rows for every sidebar entry, on every metadata refresh — O(entries × accounts) each time. This builds the account index once (HashMap with entry().or_insert, so the first row wins exactly like the previous linear search) and turns each lookup into O(1).

Change

  • One function, mailbox_entries_with_counts; no signature, type, or behaviour change.
  • No new dependencies, no new files.

User-visible effects

None intended — identical sidebar counts, computed with fewer steps. Slightly cheaper sidebar refreshes on metadata updates, most noticeable with several accounts.

Tests

  • Existing coverage for this projection (mailbox_entries_preserve_unicode_hierarchy_and_stable_ids and the src/mail.rs suite) exercises the changed function; relying on CI (cargo fmt --check, clippy, cargo test) as the gate.
  • Could not run the Rust gate locally: this contribution was prepared on a host without the Rust toolchain (no cargo/rustc), against a byte-verified copy of main (src/mail.rs blob 09cd40f, matched via git hash-object before patching).

Notes

  • Independent of the folder-sort-keys / unified-totals PRs (separate one-issue branches); P0 and the unified-totals PR touch adjacent regions of src/mail.rs, so a trivial rebase may be needed at merge time — happy to do it on request.
  • Disclosure: prepared with AI assistance (Hermes agent). I reviewed every line of the diff and confirm it is my own contribution, submitted under AGPL-3.0-only, with no credentials, mailbox data, or third-party material included.

mailbox_entries_with_counts ran a linear badge scan per sidebar entry on every metadata refresh (O(entries x accounts)). Build the account index once; first row wins, preserving the previous linear-search semantics.
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.

1 participant