V2 bootstrap takes ~5s: optimize /api/v2/bootstrap backend and first paint
维护者通常 1 天内回复
@paullizer 已经在做这个了。
开始于 2026年10月8日。
评估
这个 Issue 还没有评估数据。
描述
Summary
Make GET /api/v2/bootstrap faster so V2 renders sooner. Today the V2 shell (including the home logo, the LCP element) waits on this single call, which takes about 5s in production. Legacy pages that share the same catalog code, like /chats (p50 ~9.1s), are slow for the same reason.
User Value
- V2 first paint: ~5.6s LCP today; the target is about 1.5–2.5s.
- Legacy
/chats,/workspace, and admin pages that share_build_chat_model_catalogand the settings helpers get faster too.
Evidence (App Insights, simplechat-20260506, 3–7 days)
GET /api/v2/bootstrap: n≈877, p50 5.1s / p90 7.1s / p99 10.4s. It's the same at idle and busy hours, so it is deterministic per-request work, not load.- About 125 sequential Cosmos calls per bootstrap total only ~0.75s. Roughly 4s is uninstrumented time:
- Gap 1, p50 ~2.0s: between the
user_settingsread and the firstgroupsquery (per-user feature checks, settings and sanitize work). - Gap 2, p50 ~1.8s: between the agent governance checks and the first
promptsquery. This is_build_chat_model_catalog, which makes no Cosmos calls (endpoint normalize/sanitize withjson.loads(json.dumps())copies, model profile projection, reasoning policy, per-endpoint governance).
- Gap 1, p50 ~2.0s: between the
- N+1 query patterns: per-group
groupsreads; per-groupgroup_actions/group_agents/group_promptsqueries; ~4governance_item_policiescalls per agent. get_settings()has no in-process cache. Each call does a Redis GET,json.loads, several deepcopies, and a fullnormalize_loaded_settings.- Background pollers run inside every gunicorn web worker (2 workers × 3 instances). The workflow scheduler polls every 5s, and plan CPU averages ~12% (about one core busy). This may add GIL contention to CPU-bound request work.
Proposed Behavior
- Use the phase timings added by the quick fix (
[V2_BOOTSTRAP] Phase timingslog event) to confirm where the 4s goes before changing code. - Per-request memoization of
get_settings()and governance policy lookups; avoid repeated deepcopy/normalize. - Cache the built model catalog keyed by settings version, user, and group membership, or make its normalization cheaper.
- Batch the N+1 queries (per-group and per-agent) into
INqueries. - Split bootstrap: return critical shell data (user, branding, navigation, features, scope) first, and load the heavy catalogs (models, agents, prompts) separately so the shell and logo paint early.
- Optional ops: run background pollers outside the web workers (
SIMPLECHAT_RUN_BACKGROUND_TASKS=falseon web plus a dedicated worker), relax the 5s workflow poll, enable HTTP/2 on the App Service, and use route-level code splitting in the V2 bundle.
Acceptance Criteria
- Phase timing data reviewed and the top contributors to Gap 1 and Gap 2 identified
-
GET /api/v2/bootstrapp50 under 2s in production telemetry - V2 home LCP measurably lower; shell renders before heavy catalogs where split
- Legacy
/chatsunaffected or faster - Functional tests, version bump, fix doc and release notes per repo rules
Notes
- Related quick fix (separate change): the V2 group switch no longer waits on a full bootstrap. It uses a lightweight
/api/v2/scoperead, bootstrap reads usecache: 'no-store'so the browser can't serialize them, and bootstrap phase timing logs are added. - Key files:
route_backend_v2.py(v2_bootstrap),route_frontend_chats.py(_build_chat_model_catalog,_build_chat_prompt_catalog),functions_settings.py(get_settings,normalize_model_endpoints,sanitize_settings_for_user),app_settings_store.py,background_tasks.py,app.py(start_background_tasks),application/v2_ui/src/App.tsx. - Size estimate: L (cross-cutting backend plus frontend, shared legacy code paths).
- 主要语言
- Python
- 星标
- 155
- 派生
- 116
- 平均合并
- 5 小时 5 分钟
- 30 天内合并 PR
- 204
环境准备
在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。
- 没有 Dockerfile 或 Docker Compose 文件
- 有 Pull Request 模板
- 阅读贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
microsoft/simplechat 的其他 Issue
-
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/simplechat#1491 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 84/100
microsoft/simplechat#1370 ·
维护者通常 1 天内回复
-
Harden deployer private networking and add optional AMPLS for Commercial and Government可能已有人在做 @paullizer 于 1 天前认领。 未关闭bug enhancement P1 security_improvement
microsoft/simplechat#1765 · 已指派 1 人 ·
维护者通常 1 天内回复
-
Serve the new UI at the main URLs, move the legacy UI under /legacy, and let admins control interface access可能已有人在做 @paullizer 于 6 天前认领。 未关闭Created By Copilot enhancement P1
microsoft/simplechat#1723 · 已指派 1 人 ·
维护者通常 1 天内回复
-
V2 parity: replace the remaining hand-offs to the legacy interface so "New UI only" loses nothing可能已有人在做 @paullizer 于 6 天前认领。 未关闭Created By Copilot enhancement P1
microsoft/simplechat#1722 · 6 条评论 · 已指派 1 人 ·
维护者通常 1 天内回复
查看 microsoft/simplechat 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
aws-samples/sample-per-model-bedrock#243 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 66/100
FuRongJun-1999/dsh-memory#404 ·
维护者通常 1 天内回复
-
难度 2/5 1-3 小时 新手友好度 72/100
维护者通常 1 天内回复
-
bug frontend
难度 2/5 1-3 小时 新手友好度 68/100
PennyLaneAI/catalyst#3337 ·
维护者通常 1 天内回复
-
Workflow.schedule stops when a cron deadline passes before sleep可能已有人在做 @HuaTNA 今天认领。 未关闭
难度 2/5 1-3 小时 新手友好度 82/100
维护者通常 1 天内回复