Skip to content

perf(dashboard): O(n log k) pagination for selectVisibleTransactions - #408

Merged
Jaydbrown merged 1 commit into
conduit-protocol:mainfrom
B3rnard601:perf-375
Jul 30, 2026
Merged

perf(dashboard): O(n log k) pagination for selectVisibleTransactions#408
Jaydbrown merged 1 commit into
conduit-protocol:mainfrom
B3rnard601:perf-375

Conversation

@B3rnard601

Copy link
Copy Markdown
Contributor

What does this PR do?

Replaces the full O(n log n) sort in selectVisibleTransactions with a bounded top-k
selection, so pagination only costs work proportional to the page requested, not the
whole transaction history.

Type of change

  • Refactor / performance
  • Bug fix
  • New feature / method
  • Test coverage
  • Documentation
  • Dependency update

Related issue

Closes #375

Changes

File Change
src/dashboard/transaction-history.ts selectVisibleTransactions now uses a bounded min-heap top-k selection (O(n log k)) instead of sorting the full filtered list, with a fallback to full sort when k approaches n
src/tests/transaction-history-crash.test.ts Added tie-stability test and a brute-force cross-check across a 2,500-row dataset at 5 pages
docs/api.md New "Dashboard: Transaction History" section documenting the selectors and the perf characteristics
CHANGELOG.md Entry under [Unreleased] / Fixed

Benchmark (ms/call, uniform random timestamps, unfiltered)

n before after
1,000 0.58 0.52
10,000 3.59 0.34
50,000 26.46 2.82

Worst case (last page of a large unfiltered list, where the fallback kicks in) is a wash:
8.21ms → 8.34ms.

Checklist

  • npm run typecheck — no errors
  • npm run lint — no warnings
  • npm test — all tests pass (556/556, 2 new)
  • npm run build — bundle compiles cleanly
  • No any types introduced
  • New public methods documented in docs/api.md
  • All on-chain amounts kept as bigint — no Number() conversion in arithmetic
  • New methods mock-tested in src/tests/
  • CHANGELOG.md updated under [Unreleased]
  • src/index.ts updated if new exports added

Breaking changes?

  • No
  • Yes

Notes for reviewers

The linked issue was a placeholder with no concrete target ("module 41" doesn't exist in
the repo). I profiled the SDK to find a real hot path instead of fabricating one — this is
the most significant, defensible perf finding I could substantiate with actual benchmarks,
not synthetic numbers. Correctness matters more than speed here given this touches a
financial dashboard, so I leaned on cross-checking against a brute-force reference
implementation rather than trusting the algorithm by inspection alone.

@drips-wave

drips-wave Bot commented Jul 30, 2026

Copy link
Copy Markdown

@B3rnard601 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@Jaydbrown
Jaydbrown merged commit 6ab44c6 into conduit-protocol:main Jul 30, 2026
2 checks passed
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.

Enhancement: Detailed SDK Feature #41

2 participants