Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

V2 bootstrap takes ~5s: optimize /api/v2/bootstrap backend and first paint

未关闭
#1,725 0 条评论 0 个 reaction 已指派 1 人 在 GitHub 查看

维护者通常 1 天内回复

@paullizer 已经在做这个了。

开始于 2026年10月8日。

评估

这个 Issue 还没有评估数据。

描述

enhancement P1 python

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_catalog and 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_settings read and the first groups query (per-user feature checks, settings and sanitize work).
    • Gap 2, p50 ~1.8s: between the agent governance checks and the first prompts query. This is _build_chat_model_catalog, which makes no Cosmos calls (endpoint normalize/sanitize with json.loads(json.dumps()) copies, model profile projection, reasoning policy, per-endpoint governance).
  • N+1 query patterns: per-group groups reads; per-group group_actions/group_agents/group_prompts queries; ~4 governance_item_policies calls per agent.
  • get_settings() has no in-process cache. Each call does a Redis GET, json.loads, several deepcopies, and a full normalize_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

  1. Use the phase timings added by the quick fix ([V2_BOOTSTRAP] Phase timings log event) to confirm where the 4s goes before changing code.
  2. Per-request memoization of get_settings() and governance policy lookups; avoid repeated deepcopy/normalize.
  3. Cache the built model catalog keyed by settings version, user, and group membership, or make its normalization cheaper.
  4. Batch the N+1 queries (per-group and per-agent) into IN queries.
  5. 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.
  6. Optional ops: run background pollers outside the web workers (SIMPLECHAT_RUN_BACKGROUND_TASKS=false on 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/bootstrap p50 under 2s in production telemetry
  • V2 home LCP measurably lower; shell renders before heavy catalogs where split
  • Legacy /chats unaffected 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/scope read, bootstrap reads use cache: '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

环境准备

在 Codespaces 中打开

在浏览器里用你自己的 GitHub 账号启动这个项目的开发容器。

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

microsoft/simplechat 的其他 Issue

查看 microsoft/simplechat 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。