Skip to content

perf: 优化项目启动速度#82

Merged
insistence merged 7 commits intoinsistence:masterfrom
xy200303:optimize-startup
Feb 11, 2026
Merged

perf: 优化项目启动速度#82
insistence merged 7 commits intoinsistence:masterfrom
xy200303:optimize-startup

Conversation

@xy200303
Copy link
Contributor

@xy200303 xy200303 commented Feb 9, 2026

优化内容

  1. 网络连接优化 (utils/server_util.py):

    • 将启动时的 DNS 连通性检查 IP 从 8.8.8.8 (Google) 修改为 223.5.5.5 (阿里云),解决国内环境下启动超时或卡顿的问题。
  2. 路由扫描优化 (common/router.py):

    • 在扫描 Controller 文件时,显式跳过 .git, venv, node_modules, __pycache__ 等无关目录,大幅减少 I/O 操作。
  3. 懒加载优化 (utils/ai_util.py, utils/common_util.py, utils/excel_util.py):

    • pandas, openpyxl, agno 等重量级库实施懒加载(Lazy Loading)。
    • 仅在实际需要导出 Excel 或调用 AI 模型时才加载这些库,避免在项目启动和普通 API 调用时加载它们。
    • 显著降低了应用启动时间和内存占用。
  4. AI 服务优化 (module_ai/service/ai_chat_service.py):

    • agno 相关的重量级类导入移至 TYPE_CHECKING 块,防止在 Router 注册阶段触发不必要的模块加载。

@insistence
Copy link
Owner

ruff check没通过

@insistence
Copy link
Owner

感谢贡献,我重新做了下调整:
1.网络连接优化保留,进一步做了细节优化。
2.路由扫描优化进行了重构,使用glob替代os.walk全目录递归遍历,并使用module.__dict__.items()替代dir(module) + getattr
3.懒加载优化只保留对ai_util.py的修改并做了一些调整,实际测试pandas影响不是很大。
4.AI 服务优化移除了,实际测试影响较小。
5.修复了ruff check错误。

@insistence insistence changed the title perf: 优化项目启动速度与模块加载效率 perf: 优化项目启动速度 Feb 11, 2026
@insistence insistence merged commit f41aa19 into insistence:master Feb 11, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants