Is beartype cost acceptable?
还没有人认领这个 Issue。
评估
- 难度
- 5/5
- 预计耗时
- 一周以上
- 新手友好度
- 35/100
- Issue 类型
- 重构
- 描述清晰度
- 需要澄清
- 活跃度
- 冷清
- 技术栈
- python
- 领域
- performance
调研方向
从 zimscraperlib/init.py 和 beartype_this_package() 调用开始,然后检查 zimscraperlib.rewriting 热路径以及文档中记录的 warc2zim 基准测试命令。如有需要,重新执行成对运行,并比较实际耗时、CPU 时间和峰值 RSS。完成的标准是就 coverage 是否应限定范围、使用成本更低的策略进行配置,或针对选定的运行禁用达成共识并完成记录。
由索引模型根据 Issue 内容生成。
描述
Context
While investigating a memory leak (fixed in #324 — a closure in RxRewriter.rewrite() was being re-decorated by beartype's claw hook on every call, permanently pinning it via beartype's own is_object_blacklisted cache), the fix removed the leak but also raised the question of how much runtime cost beartype_this_package() (used project-wide in zimscraperlib/__init__.py) actually adds. This issue is to share those numbers and discuss whether the tradeoff is the one we want.
Methodology
Ran warc2zim to completion, twice, on the same input, same machine, back to back:
warc2zim --publisher=openZIM --content-header-bytes-length=2048 \
--zim-file=www.physicsclassroom.com_56e21a6e.zim --name=www.physicsclassroom.com_56e21a6e \
--scraper-suffix "zimit 3.1.2" --output output \
--url https://www.physicsclassroom.com/ \
<local WARC, 731MB compressed, ~14.5K ZIM entries> --overwrite
wrapped in /usr/bin/time -v for wall-clock, CPU, and peak RSS.
- Run A:
zimscraperlibas-is (beartype_this_package()active). - Run B: same install, with the single line
beartype_this_package()inzimscraperlib/__init__.pycommented out (everything else identical), bytecode cache cleared between runs.
Both runs post-date the #324 leak fix, so memory is no longer confounded by that bug.
Results
| With beartype (Run A) | Without beartype (Run B) | Delta | |
|---|---|---|---|
| Wall clock time | 53:50 (3230s) | 44:08 (2648s) | −18.0% |
| User CPU time | 3835s | 3251s | −15.2% |
| Max RSS | 924,060 KB | 885,356 KB | −4.2% (noise-level) |
Both runs completed successfully with an identical entry count. Memory is essentially the same between the two (the small gap is within run-to-run noise).
Takeaway
Runtime type-checking via beartype_this_package() costs roughly 15-18% additional wall-clock/CPU time on this workload, with no meaningful memory cost of its own now that #324 is fixed.
Discussion
Is this tradeoff (broad runtime type-safety across zimscraperlib, for ~15-18% slower conversions) the one we want, or should beartype's coverage be scoped down — e.g. excluding hot paths like zimscraperlib.rewriting from beartype_this_package(), or using a cheaper BeartypeStrategy for those modules — while keeping full checking elsewhere, or allowing to fully disable beartype "on-demand" (e.g. enable it only for unit and e2e tests of scraperlib and scrapers)?
- 主要语言
- Python
- 星标
- 31
- 派生
- 27
- 平均合并
- 3 天 7 小时
- 30 天内合并 PR
- 2
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
openzim/python-scraperlib 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 72/100
openzim/python-scraperlib#339 ·
-
enhancement
难度 2/5 1-3 小时 新手友好度 68/100
openzim/python-scraperlib#292 ·
-
bug
难度 4/5 3-5 天 新手友好度 35/100
openzim/python-scraperlib#341 ·
-
bug
难度 3/5 1-2 天 新手友好度 45/100
openzim/python-scraperlib#340 ·
-
bug
openzim/python-scraperlib#334 · 已指派 1 人 ·
查看 openzim/python-scraperlib 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 74/100
bancolombia/sentinel#23 ·
-
test md 未关闭CI
难度 2/5 1-3 小时 新手友好度 74/100
-
integration:quickjs org:external priority:backlog topic:code-interpreter topic:middleware type:feature
难度 2/5 1-3 小时 新手友好度 74/100
langchain-ai/deepagents#6450 ·
-
bug client
难度 2/5 1-3 小时 新手友好度 88/100
-
难度 2/5 1-3 小时 新手友好度 74/100