Skip to content

Tokens Service Performance Improvements#1598

Draft
stefangutica wants to merge 4 commits intodevelopmentfrom
tokens-improvements
Draft

Tokens Service Performance Improvements#1598
stefangutica wants to merge 4 commits intodevelopmentfrom
tokens-improvements

Conversation

@stefangutica
Copy link
Copy Markdown
Collaborator

Reasoning

  • Token processing had two major performance bottlenecks: repeated full-array filtering passes and repeated linear identifier lookups.
  • In high-cardinality token datasets, these patterns increase CPU usage and allocation pressure, especially on frequently used endpoints.
  • This PR improves performance by minimizing repeated scans and enabling cached key-based access for reused token arrays.

Proposed Changes

  • Refactored getFilteredTokens() to evaluate all active filters in a single Array.filter() pass with early exits.
  • Precomputed normalized filter inputs once per request (search/name/identifier/identifiers and mexPairType values) to avoid repeated string operations.
  • Introduced ArrayIndexer backed by WeakMap to cache per-array, per-property positions and provide near O(1) lookups after first index build.
  • Replaced multiple identifier-based linear searches in TokenService and CacheWarmerService with ArrayIndexer.getItemByKeyValue(...).
  • Preserved functional behavior and sorting semantics while reducing redundant work in hot paths.

How to test

  • Run existing token and cache warmer test suites and verify no behavioral regressions.
  • Validate filter combinations (search, name, identifier, identifiers, includeMetaESDT, mexPairType, priceSource) and confirm output parity.
  • Validate token retrieval, token-with-balance, and token-with-roles flows for both existing and missing identifiers.
  • Compare before/after latency and CPU consumption using representative load tests on large token lists.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Apr 21, 2026

k6 load testing comparison.
Base Commit Hash: 79b2062
Target Commit Hash: 119b26b

Metric Base Target Diff
AvgMax9095AvgMax9095AvgMax9095
Accounts94.11664.90296.90331.5470.451377.33101.79123.57-25.14% ✅+107.15% 🔴-65.71% ✅-62.73% ✅
Transactions694.8449377.95106.13107.9782.212183.12111.93122.80-88.17% ✅-95.58% ✅+5.47% 🔴+13.73% 🔴
Mex88.40767.22212.44327.3361.70339.0366.3168.96-30.20% ✅-55.81% ✅-68.78% ✅-78.93% ✅
Pool90.82760.51265.92328.7763.361263.5866.4869.10-30.24% ✅+66.15% 🔴-75.00% ✅-78.98% ✅
Blocks114.34870.17371.55436.1272.711404.5778.6590.07-36.41% ✅+61.41% 🔴-78.83% ✅-79.35% ✅
Nodes986.5035748.13214.82360.0661.90339.0766.2869.04-93.72% ✅-99.05% ✅-69.15% ✅-80.83% ✅
Tokens91.25800.49272.95329.5362.49543.8866.4669.02-31.52% ✅-32.06% ✅-75.65% ✅-79.05% ✅
Test Run Duration60003.1760006.11

Legend: Avg - Average Response Time, Max - Maximum Response Time, 90 - 90th Percentile, 95 - 95th Percentile
All times are in milliseconds.

@stefangutica stefangutica marked this pull request as draft April 23, 2026 06:38
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