Lazy-load non-essential blueprints to improve desktop startup

未关闭
#10,221 8 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 2 天内回复

还没有人认领这个 Issue。

评估

难度
5/5
预计耗时
一周以上
新手友好度
38/100
Issue 类型
重构
描述清晰度
需要澄清
活跃度
活跃
技术栈
electron, python

调研方向

Start by tracing create_app() and running the three python -X importtime commands listed in the issue, then compare those results with overall startup time. Review authenticate/registry.py and the blueprint loading paths for tools, llm, and dashboard. Done means a measured, agreed scope for lazy loading that preserves the essential desktop startup flow.

由索引模型根据 Issue 内容生成。

描述

Housekeeping

Problem

Some blueprints are imported during create_app() even though they are not required for desktop startup (SERVER_MODE=False). If we only import essential blueprints on startup and lazy load the other this would definetly result in faster load times.

After tracing the startup flow here is a breakdown of the blureprints and how we should ideally load them:

Modules that should remain eagerly loaded

Module Reason
misc Provides the /misc/ping endpoint that Electron polls while waiting for the backend to start. Without it, the application never gets past the splash screen.
browser Hasindex(), the first page Electron loads after startup. Deferring it only shifts the wait from the splash screen to a blank window. preferences also depends on it.
Core authenticate Required for session and login handling, even in desktop mode.

Good lazy-loading candidates

Module Load when Reason Approx. size
authenticate (kerberos, ldap, mfa, oauth2, webserver) Never in desktop mode Gate imports in authenticate/registry.py behind config.SERVER_MODE. Desktop runs with SERVER_MODE=False and doesn't use these providers. ~14 files
tools First tool opens Query Tool, Debugger, Backup/Restore, ERD, Import/Export, etc. aren't needed during startup. ~155 files
llm AI assistant opened Depends on pgadmin.tools.user_management, so it would likely move together with tools. ~32 files
dashboard First server/database opened The dashboard isn't shown until after a connection is opened. ~7 files

Note: Considering how often tools are used, we can keep the tools blueprint in the early-loading category for a few select tools.

Not worth lazy-loading

These modules are tiny (1–4 files each):

  • preferences
  • settings
  • about
  • help
  • redirects

Estimated impact

Potentially removes eager imports for roughly:

  • tools
  • llm
  • External authentication backends

≈ 190 of ~915 Python files

File count is only a rough proxy and not an estimate of startup improvement.

Validation

Profile import costs:

python -X importtime -c "from pgadmin.tools import blueprint"
python -X importtime -c "from pgadmin.llm import blueprint"
python -X importtime -c "from pgadmin.authenticate.registry import AuthSourceRegistry"

Then compare against overall create_app() startup time.

Proposal

  • Gate external auth provider imports behind config.SERVER_MODE.
  • Lazy-load tools on first use.
  • Lazy-load llm together with tools.
  • Optionally lazy-load dashboard if it can be done cleanly.

I would be happy to start from the authenticate change since it's small and self-contained.

This is not a concrete implementation proposal, but rather a summary of observations from tracing the desktop startup flow and a few areas that might be worth exploring. I have not profiled import times yet but plan to do so shortly, so these suggestions are based on the current startup path and module dependencies rather than measured performance. However, I will shortly run the performance tests and provide details as a follow-up to this issue.

I would also appreciate some guidance on whether these are the right areas to target, or if there is a better approach I'm overlooking.

Thanks

主要语言
Python
星标
3.9k
派生
918
平均合并
2 天 12 小时
30 天内合并 PR
35

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

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

pgadmin-org/pgadmin4 的其他 Issue

查看 pgadmin-org/pgadmin4 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

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