V2 bootstrap takes ~5s: optimize /api/v2/bootstrap backend and first paint
Maintainer thường phản hồi trong vòng 1 ngày
@paullizer đang làm issue này rồi.
Từ ngày 8/10/2026.
Đánh giá
Issue này chưa được đánh giá.
Mô tả
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).
- Ngôn ngữ chính
- Python
- Star
- 155
- Fork
- 116
- Merge trung bình
- 7 giờ 40 phút
- Pull request đã merge (30 ngày)
- 175
Chuẩn bị môi trường
Khởi chạy dev container của dự án ngay trên trình duyệt, bằng tài khoản GitHub của bạn.
- Không có Dockerfile hay tệp Docker Compose
- Có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của microsoft/simplechat
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/simplechat#1491 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 84/100
microsoft/simplechat#1370 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Serve the new UI at the main URLs, move the legacy UI under /legacy, and let admins control interface accessCó thể đã có người làm @paullizer đã nhận 6 ngày trước. Đang mởCreated By Copilot enhancement P1
microsoft/simplechat#1723 · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
V2 parity: replace the remaining hand-offs to the legacy interface so "New UI only" loses nothingCó thể đã có người làm @paullizer đã nhận 6 ngày trước. Đang mởCreated By Copilot enhancement P1
microsoft/simplechat#1722 · 6 bình luận · 1 người được giao ·
Maintainer thường phản hồi trong vòng 1 ngày
-
enhancement
Độ khó 5/5 Hơn một tuần Mức phù hợp với người mới 15/100
microsoft/simplechat#1719 ·
Maintainer thường phản hồi trong vòng 1 ngày
Tất cả issue của microsoft/simplechat
Issue tương tự
-
customer-reported question
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Azure/azure-sdk-for-python#49548 · 1 bình luận · 1 reaction ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
btclib-org/btclib-wallet#409 ·
Maintainer thường phản hồi trong vòng 1 ngày
-
Phase 2 PSA Capability & Career Profile
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
bcgov/digital-journeys#2310 ·
-
bug good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
fastmachinelearning/hls4ml#1582 ·
Maintainer thường phản hồi trong vòng 3 ngày
-
Sort modelsĐang mởenhancement good first issue
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 62/100
Maintainer thường phản hồi trong vòng 1 ngày