Optimize performance: defer module loading and reduce polling intervals - #2424
Open
MusabShakeel576 wants to merge 1 commit into
Open
Optimize performance: defer module loading and reduce polling intervals#2424MusabShakeel576 wants to merge 1 commit into
MusabShakeel576 wants to merge 1 commit into
Conversation
…onds
Three separate causes behind the slow launch, addressed in the order they
cost the user time.
Cold start. Sentry's app.start.cold spans put ~94% of a 4.7s cold start
in "JS Bundle Execution Before React Root" — no network involved, just
Metro evaluating every module in the graph before React renders, because
it hoists every require to the top of its module. Metro now defers each
require to its first point of use. Modules imported for their side
effects rather than their exports are pinned in nonInlinedRequires: the
polyfill chain index.js deliberately orders, plus NativeWind's CSS
interop. experimentalImportSupport is restated because returning this
object replaces Expo's own getTransformOptions instead of merging.
Sentry's profiler and mobile session replay both ran on half of all
sessions, alongside Amplitude's replay plugin, on hardware where every
session I sampled came from a low-end Android device. Both drop to a
tenth; replays on error are untouched.
Login. handleLogin awaited six things before navigating. Two of them do
not need to be there. safeAA existed only to read an address the login
response already returned, at the cost of a Turnkey round trip plus the
RPC calls toSafeSmartAccount makes — the smart-account client itself is
only needed to sign, and the flows that sign build it themselves. It is
now the fallback for an account with no address on file, which is the
same condition that already triggered the sync. checkBalance and
fetchPoints are started rather than awaited; both re-run in
usePostSignupInit once the app is up.
Polling. An idle home screen was issuing ~370 requests a minute: token
balances every 5s (19 parallel calls plus the token processing each
time), vault balances every 3s, card balance and native prices every 5s.
useActivitySSE already invalidates both tokenBalances and vault on a
balance event, so these are a fallback and now run like one. This is also
the most plausible source of the 210k upstream-connection 503s in Sentry,
where the app is on both ends of the loop.
Also: Blockscout had no timeout on either call path, so a stalled
explorer held the balance skeleton open indefinitely — both now carry the
same deadline as Alchemy. Blockscout and LI.FI moved off the global axios
instance, which attaches the user's access token to every request on
native. The interceptor's missing-token warning now fires only for calls
to our own services, instead of once per public request.
useTotalVaultBalance awaited each vault's chains in turn; one Promise.all
covers all of them. publicClient built a fresh viem client per call, seven
times per token-balance run, on a timer.
Corrects a wrong note in lib/wagmi.ts: multicall batching was never off.
@wagmi/core's createConfig defaults batch to { multicall: true }, so the
commented-out line was a no-op and uncommenting it would change nothing.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01UNaLEk8QE73jaaW6pbRef4
|
The latest updates on your projects. Learn more about Vercel for GitHub. 2 Skipped Deployments
|
Code reviewNo issues found. Checked for bugs and CLAUDE.md compliance. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
This PR significantly improves app performance by deferring non-critical module evaluation, reducing unnecessary polling intervals, and optimizing data fetching patterns. The changes focus on reducing CPU usage on low-end devices and improving perceived responsiveness during login.
Key Changes
Module Loading Optimization (metro.config.js)
inlineRequiresto defer module evaluation until first use, moving ~94% of cold start time from "JS Bundle Execution Before React Root" to when modules are actually needednonInlinedRequiresto preserve eager loading for ordering-sensitive polyfills and React runtimeLogin Flow Optimization (hooks/useUser.ts)
safeAAderivation when the login response already contains the safe addresscheckBalanceandfetchPointsnon-blocking by removingawait, allowing navigation to proceed while these background queries completePublic Client Caching (lib/wagmi.ts)
Polling Interval Reductions
All polling intervals now serve as fallbacks for SSE/real-time updates rather than primary data sources, reducing unnecessary requests from idle clients.
Request Timeout & Error Handling
Sentry Sampling Adjustments (app/_layout.tsx)
Query Optimization (hooks/useVault.ts)
Implementation Details
https://claude.ai/code/session_01UNaLEk8QE73jaaW6pbRef4