commit
Add temporary per-stage timing logs to profile builds
Diagnosing a profile fetch still taking ~11s after parallelizing wishlist/collectible resolution — need to see which stage is actually slow before touching anything else. Co-Authored-By: Claude Sonnet 5 <[email protected]>
diff --git a/src/profile.ts b/src/profile.ts
index 8e9248d..c6d3d1b 100644
--- a/src/profile.ts
+++ b/src/profile.ts
@@ -616,9 +616,11 @@ async function buildFreshProfile(
force = false
): Promise<BuildResult> {
// Rich path first (unless we're cooling down from a 429); fall back to bot.
+ const _t0 = Date.now();
const rich = tryRich
? await fetchUserProfile(env, id)
: { data: null, status: 0, retryAfter: 0 };
+ console.log(`[timing] fetchUserProfile: ${Date.now() - _t0}ms (status=${rich.status})`);
const richStatus = rich.status;
const retryAfter = rich.retryAfter;
const profile = rich.data;
@@ -666,15 +668,19 @@ async function buildFreshProfile(
// Fetch everything that doesn't depend on the profile body in parallel.
// Wishlist + equipped collectibles need the profile, so they run alongside.
+ const _timed = <T,>(label: string, p: Promise<T>): Promise<T> => {
+ const start = Date.now();
+ return p.finally(() => console.log(`[timing] ${label}: ${Date.now() - start}ms`));
+ };
const [wishlist, collectibles, clientBadges, memberships, pronoundb, timezone, reviews] =
await Promise.all([
- buildWishlist(env, profile, ctx, force),
- buildCollectibles(env, profile, ctx, force),
- getClientBadges(env, id, ctx, force),
- getMemberships(env, id, ctx, force).catch(() => null),
- getPronouns(env, id, ctx, force).catch(() => null),
- getTimezone(env, id, ctx, force).catch(() => null),
- getReviews(env, id, ctx, force).catch(() => null),
+ _timed("buildWishlist", buildWishlist(env, profile, ctx, force)),
+ _timed("buildCollectibles", buildCollectibles(env, profile, ctx, force)),
+ _timed("getClientBadges", getClientBadges(env, id, ctx, force)),
+ _timed("getMemberships", getMemberships(env, id, ctx, force).catch(() => null)),
+ _timed("getPronouns", getPronouns(env, id, ctx, force).catch(() => null)),
+ _timed("getTimezone", getTimezone(env, id, ctx, force).catch(() => null)),
+ _timed("getReviews", getReviews(env, id, ctx, force).catch(() => null)),
]);
return {