Skip to content

perf(registry): hash-indexed point lookups instead of linear scans - #94

Merged
amanusk merged 1 commit into
masterfrom
perf/registry-hash-lookups
Sep 13, 2026
Merged

amanusk merged 1 commit into
masterfrom
perf/registry-hash-lookups

Conversation

@amanusk

@amanusk amanusk commented Sep 13, 2026

Copy link
Copy Markdown
Owner

Problem

AddressRegistry::resolve, is_known, is_privacy_address, resolve_tx, get_decimals, get_metadata, format_address_full and viewing_key each scanned the user-label, known-address and tx-label Vecs with iter().find(). Every rendered address row calls three to five of them, and the address-tab color-map rebuild (update_tx_color_map / update_call_color_map) calls is_known for every row whenever the list grows, which for a busy contract is on every WS event. With ~760 user labels that was ~40M Felt compares per event on the UI thread.

Closes #90.

Change

  • load() builds Felt → index HashMaps for user labels, known addresses, tx labels and viewing keys, plus a HashSet<Felt> of type = "Privacy" known addresses. First occurrence wins, matching the old find semantics. The known-address dedup during index build uses the map too.
  • All point lookups route through two private helpers (user_label, known_addr) or the maps directly. Iteration-only methods (privacy_addresses, iter_viewing_keys, search, resolve_by_name, add_voyager_label) are unchanged.

Bench

Release profile, same TestBackend harness as #93, 52k rows (temporary example, not committed):

Measurement Before After
3 lookups per row over all 52k rows, 759 labels 73 ms 5 ms
Same with 0 labels 5 ms 3 ms
Txs tab frame, 759 labels 1.1 ms 0.7 ms
Calls tab frame including color-map rebuild (fires per WS event) — 2.5 ms

Lookup cost is flat in label count now.

Tests

  • New: a user label shadowing the bundled Privacy Pool keeps is_privacy_address true and get_decimals still resolves through a user-shadowed known entry; viewing-key lookup by user address.
  • cargo test, cargo clippy --all-targets (no new warnings), cargo build --release.

Follow-ups

🤖 Generated with Claude Code

resolve/is_known/is_privacy_address/resolve_tx/get_decimals/
get_metadata/viewing_key each scanned the user, known and tx-label Vecs
with `find`. Rendered rows call three to five of them, and the address
color-map rebuild calls is_known for every row whenever the list grows,
which on a busy contract is every WS event.

Build Felt -> index HashMaps (first occurrence wins, matching `find`)
and a HashSet of privacy addresses once in load(); route all point
lookups through them. Iteration-only methods are unchanged.

Bench (release, 52k rows, 759 user labels):
3 lookups per row over all rows: 73 ms -> 5 ms, flat in label count.
Txs tab frame 1.1 ms -> 0.7 ms; frame with color-map rebuild 2.5 ms.

Closes #90.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@amanusk amanusk added performance Performance: latency, throughput, resource usage snbeat Main snbeat TUI binary labels Sep 13, 2026
@amanusk
amanusk requested a lite review from Copilot September 13, 2026 14:07

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟢 Approval recommended

No unresolved issues were identified.

Pull request overview

Improves AddressRegistry lookup performance by replacing linear scans with hash-based indexes while preserving lookup behavior.

Changes:

  • Adds indexes for labels, known addresses, transactions, viewing keys, and privacy addresses.
  • Routes point lookups through the new indexes.
  • Adds regression tests for shadowing and viewing-key lookup.
File summaries
File Summary
tests/registry_test.rs Covers lookup behavior and shadowing semantics.
src/registry/mod.rs Implements indexed registry lookups and privacy classification.
Review details
  • Files reviewed: 2/2 changed files
  • Comments generated: 0
  • Review effort level: Lite

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@amanusk
amanusk merged commit 569ccda into master Sep 13, 2026
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

performance Performance: latency, throughput, resource usage snbeat Main snbeat TUI binary

Projects

None yet

Development

Successfully merging this pull request may close these issues.

perf(registry): address/tx label lookups are linear scans, called several times per rendered row

2 participants