Engineering Methods for Client Startup Optimization and LLM Gray-Release Evaluation
This article explains how to measure and reduce client startup time, design cached list loading and search indexes, and evaluate AI agents in gray releases. It covers success criteria, sample size planning, significance testing, and staged rollout checks.
1. Metrics and Measurement Scope
Slow client startup reduces how often users open the app. Fluctuations in large language model (LLM) capability reduce users’ trust in the output. Both problems require answers to two questions: Is the experience faster? And once it is faster, is it reliable?
The team should define metrics first and document the measurement scope. Otherwise, results from two measurements cannot be compared.
- Cold start time: The time from the user tapping the app until the interface becomes interactive, when the app is not running.
- Warm start time: The time to bring the interface back when the app is already running in the background.
- Percentiles: Track both P50 and P95. Averages hide the long tail that a minority of users experience as lag.
- Measurement scope: Record the test device model, OS version, network type (Wi-Fi, 4G, or simulated weak network), sample size, client version, and sampling period. Use the same scope for every comparison.
- Model capability metrics: Single-task success rate, all-runs success rate, and number of steps to task completion.
- Availability metrics: Request error rate and timeout rate.
Brief interruptions are availability issues, while capability differences are model issues. Record and attribute them separately. If the two are mixed, the team will struggle to identify the real cause of problems in a new version.
2. Startup Optimization and List Caching
2.1 Startup Time Breakdown
Instrument each stage before optimizing. Otherwise, the team may focus on stages that account for a small share of total time. The table below is a breakdown template. Fill in the proportions after measuring on real devices.
| Stage | Instrumentation point | Metric of interest | Common optimization directions |
|---|---|---|---|
| Process creation | Process entry point | Time from process launch to main process ready | Reduce synchronous dependencies at startup |
| Runtime initialization | Runtime load completed | Initialization time | Defer non-essential modules |
| Main screen resource loading | Resource request start and end | First-screen bundle size, loading time | Load on demand, split code into chunks |
| First render | First frame submitted | Time to first frame | Mount dialogs late, reduce nodes on the first screen |
| Remote data request | Request sent and response received | Time for first-screen data to arrive | Cache first, refresh in background |
Four common optimizations apply. On-demand loading splits non-first-screen modules into separate code chunks. Prefetching loads the data users are most likely to need on frequently visited pages during idle time. The team should record the prefetch hit rate, because a low hit rate means prefetching only wastes bandwidth. Dialogs are created only when first triggered. Compute-heavy work such as parsing, compression, and index building runs in worker threads to reduce main-thread load.
2.2 List Cache Invalidation and Concurrency Steps
Loading from cache first shortens the wait for the first screen. However, cached data may be stale, and it may not match the current account state. Follow these steps when implementing it:
- Design the cache key: Include an account identifier, the data type, and a schema version in the key, for example
user:{hash(uid)}. Hash the account identifier with a salt first. Never write the real user identifier to cache keys or logs.
v3 - Record metadata: Store the write time, server version number, and TTL with each cache entry. After the TTL expires, the entry can still be displayed but should be marked as pending refresh. After the maximum retention period, delete it.
- Deduplicate concurrent requests: For the same key, send only one network request at a time. Other callers wait on the same Promise.
- Check versions: Discard any response whose version number is lower than the locally known version. This prevents an old response that arrives out of order from overwriting newer data.
- Retry and timeout: Retry only retryable errors, such as network-layer errors, 408, 429, and 5xx. Retry up to 3 times, with exponential backoff capped at 8 seconds and random jitter. Set a 10-second timeout for each request. Do not retry authentication failures or 400-class parameter errors.
- Fall back on failure: If the network request fails, keep showing the cached data and indicate that it may be outdated. If there is no cache and the request fails, show a clear error state.
- Invalidation triggers: Clear the relevant cache keys when the account switches, the user logs out, the client is upgraded, the schema changes, or the user refreshes manually. When the account switches, also cancel that account’s pending requests.
- Sensitive data: Do not write tokens or plaintext sensitive fields to the cache. On logout, clear all cache entries for that account.
The following is an illustrative code sample. fetcher accepts an AbortSignal parameter and returns { data, version }. Before release, list rendering also needs diff-based updates. This sample does not cover that part.
const cache = new Map(); // key -> { data, version, savedAt }const inflight = new Map(); // key -> Promise, used to deduplicate concurrent requestsconst TTL_MS = 5 * 60 * 1000;const MAX_AGE_MS = 24 * 60 * 60 * 1000;const MAX_RETRIES = 3;const BASE_DELAY_MS = 500;const MAX_DELAY_MS = 8000;const REQUEST_TIMEOUT_MS = 10000;const RETRYABLE_STATUS = new Set([408, 429, 500, 502, 503, 504]);const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));function isRetryable(err) {if (err.status === undefined) return true; // Network-layer errorreturn RETRYABLE_STATUS.has(err.status);}function backoffDelay(attempt) {const exp = Math.min(MAX_DELAY_MS, BASE_DELAY_MS * 2 ** attempt);return Math.random() * exp; // Full jitter}async function fetchWithRetry(fetcher) {for (let attempt = 0; ; attempt++) {const controller = new AbortController();const timer = setTimeout(() => controller.abort(), REQUEST_TIMEOUT_MS);try {return await fetcher(controller.signal);} catch (err) {const timedOut = err.name === 'AbortError';if (attempt >= MAX_RETRIES || (!timedOut && !isRetryable(err))) throw err;await sleep(backoffDelay(attempt));} finally {clearTimeout(timer);}}}async function loadList(key, fetcher, render) {const entry = cache.get(key);const now = Date.now();if (entry) {if (now - entry.savedAt < MAX_AGE_MS) {render(entry.data, { stale: now - entry.savedAt > TTL_MS });} else {cache.delete(key); // Past the maximum retention period, discard}}if (!inflight.has(key)) {inflight.set(key, fetchWithRetry(fetcher).finally(() => inflight.delete(key)));}try {const fresh = await inflight.get(key);const current = cache.get(key);if (current && fresh.version < current.version) return; // Discard stale responsecache.set(key, { data: fresh.data, version: fresh.version, savedAt: Date.now() });render(fresh.data, { stale: false });} catch (err) {if (!cache.has(key)) {render(null, { error: true }); // No cache and the request failed, show error state} else {console.warn('Refresh failed, keeping existing cache', key, err.name);}}}
Logs should record only the error type and a hash of the key. Do not log response bodies, to avoid leaking list content.
3. Search Index Design
The search index should let users find results within an acceptable time, without exposing content they are not authorized to
