Skip to content

perf: skip 3s DWN discovery for returning users and parallelize registration#78

Open
LiranCohen wants to merge 1 commit into
mainfrom
perf/startup-optimizations
Open

perf: skip 3s DWN discovery for returning users and parallelize registration#78
LiranCohen wants to merge 1 commit into
mainfrom
perf/startup-optimizations

Conversation

@LiranCohen

Copy link
Copy Markdown
Contributor

Summary

Addresses slow wallet unlock and page reload by fixing the two biggest bottlenecks in the wallet's initialization path.

Depends on: enboxorg/enbox#871 (platform-level perf fixes). The wallet changes here are independent — they fix wallet-specific bottlenecks. The enbox PR fixes platform bottlenecks that affect all consumers.

Changes

Skip 3-second DWN discovery wait for returning users (provider.tsx)

The init() function unconditionally waited 3 seconds for local DWN discovery on every desktop page load — even when the user has a cached session PIN (i.e., a returning user refreshing the tab). This blocked the entire auth initialization pipeline.

Fix:

  • Skip discovery entirely when a cached session PIN exists (sessionStorage). Returning users already have persisted endpoints.
  • When discovery does run (first-time setup), resolve early via hashchange event if the local DWN responds before the timeout, instead of always burning the full 3 seconds.

Parallelize DWN tenant registration (registration.ts)

ensureRegistration() was iterating endpoints sequentially, and within each endpoint iterating DIDs sequentially. With 2 endpoints and 3 identities, that's 8 sequential HTTP round-trips.

Fix:

  • Fetch serverInfo for all endpoints concurrently via Promise.allSettled().
  • Register all DIDs on all reachable endpoints concurrently via Promise.all().
  • Merge token updates from all registrations.

Expected Impact

Scenario Before After
Cached-PIN page refresh (desktop) ~4s+ (3s discovery + vault + sync) ~1s (discovery skipped)
First-time setup with responsive local DWN Always 3s wait Resolves immediately on hashchange
Post-unlock DWN registration (2 endpoints × 4 DIDs) ~8 sequential HTTP requests ~2 parallel batches

Verification

  • TypeScript: npx tsc --noEmit passes
  • Build: bun run build passes
  • ESLint: Clean on modified files

…tration

Skip the unconditional 3-second local DWN discovery wait when the user
has a cached session PIN (returning user). Also resolve early via
hashchange event if the local DWN responds before the timeout.

Parallelize DWN tenant registration: fetch server info for all endpoints
concurrently, then register all DIDs on all reachable endpoints in
parallel instead of sequential endpoint x DID nested loops.
@github-actions

github-actions Bot commented Apr 9, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 27.38% (🎯 25%) 552 / 2016
🔵 Statements 26.82% (🎯 25%) 605 / 2255
🔵 Functions 32.4% (🎯 30%) 186 / 574
🔵 Branches 31.42% (🎯 29%) 455 / 1448
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/enbox/provider.tsx 0% 0% 0% 0% 29-426
src/enbox/registration.ts 0% 0% 0% 0% 22-189
Generated in workflow #234 for commit 63c2365 by the Vitest Coverage Report Action

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