Skip to content

Performance: Logs - Metrics for createKey and Import#2082

Draft
cmgustavo wants to merge 5 commits intobitpay:masterfrom
cmgustavo:draft/performance-metrics-createkey-import-01
Draft

Performance: Logs - Metrics for createKey and Import#2082
cmgustavo wants to merge 5 commits intobitpay:masterfrom
cmgustavo:draft/performance-metrics-createkey-import-01

Conversation

@cmgustavo
Copy link
Member

Performance Analysis – createKey & serverAssistedImport

This PR adds instrumentation and analyzes app-side performance for wallet creation and import flows.

Results

createKey (11 wallets)

  • Total: ~36.6s
  • createMultipleWallets: ~29.6s (~81%)
  • BWC.createKey: ~7.0s (~19%)

serverAssistedImport (36 wallets, 14 tokens)

  • Total: ~77.1s
  • serverAssistedImport: ~64.0s (~83%)
  • createWalletsForAccounts: ~12.9s (~17%)

Key Findings

  • Bottlenecks are not UI-related (Redux/object building negligible)
  • Main costs:
    • Wallet creation (createWallet)
    • Address generation (createWalletAddress)
    • Server-assisted import scan
  • Execution is mostly sequential (~2.7s per wallet)
  • Import has wasted work (COPAYER_REGISTERED retries)
  • Post-import address hydration can take 14–17s per wallet

Optimization Targets

  1. Stream import results to unblock UI
  2. Avoid duplicate wallet creation attempts
  3. Parallelize wallet + address creation where safe
  4. Defer/lazy-load address generation
  5. Investigate BWC.createKey (~7s)

@cmgustavo
Copy link
Member Author

createKey took 36.65s end-to-end for 11 wallets on livenet.

Biggest bottlenecks:

  • createMultipleWallets.TOTAL: 29.65s (80.9%)
  • createKey.BWC.createKey: 6.97s (19.0%)

Per-wallet average:

  • ~2.70s per base wallet flow

Main repeated costs:

  • createWallet.TOTAL: generally 1.45s–1.98s
  • createWalletAddress.TOTAL: generally 0.86s–1.61s

Worst address-generation cases:

  • XRP: 1.61s
  • ETH: 1.33s
  • MATIC/BASE/OP/ARB: about 1.23s–1.25s

Negligible:

  • buildWalletObjectsAndSubscriptions: 66ms
  • buildKeyObj: 1.4ms
  • success dispatch: 28ms

Conclusion: the real app-side optimization targets are root key generation, sequential wallet creation, and address generation. Redux/object-building is not the problem.

@cmgustavo
Copy link
Member Author

serverAssistedImport import run took 77.11s end-to-end.

Biggest bottlenecks:

  • serverAssistedImport.API.callback: 64.02s (83.0%)
  • import.createWalletsForAccounts: 12.86s (16.7%)

Imported result:

  • 36 wallets
  • 14 token wallets

Negligible:

  • dedupe: 0.1ms
  • token linking: 13.4ms
  • key matching: 0.8ms
  • object build: 196.1ms

Important note:

  • follow-up account wallet creation is hitting repeated bwc.ErrorCOPAYER_REGISTERED failures for ETH/MATIC/ARB/BASE/OP/SOL
  • after import completes, there is also very expensive getLatestMainAddress hydration on many wallets/tokens, which likely contributes to UI still feeling busy

Conclusion: the real import bottlenecks are the server-assisted discovery scan first, then post-import account wallet creation. Token linking and object-building are not the problem.

@cmgustavo
Copy link
Member Author

Fixed: response when click on Create Key (during onboarding)

New changes, commit: 3ae78eb

Controlled concurrency in createMultipleWallets reduced createKey.TOTAL from 36.65s to 20.70s for 11 wallets.

That is:

  • ~15.95s faster
  • ~43.5% improvement
  • ~1.77x speedup

This strongly validates that the previous sequential wallet creation flow was a major bottleneck.

@cmgustavo
Copy link
Member Author

cmgustavo commented Mar 18, 2026

Import improved from ~77.5s to ~66.1s for 36 wallets after removing duplicate wallet creation work. 05ee108

Next optimization step is to defer and chunk wallet address/funds scanning so import can complete earlier and wallet hydration can continue in the background.

@cmgustavo cmgustavo force-pushed the draft/performance-metrics-createkey-import-01 branch from 05ee108 to 3d0d59d Compare March 20, 2026 20:41
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