arXiv:2605.21405cs.SEcs.AI2026-05被引 1

用大模型重写40多个第三方库,验证纯标准库能否替代且更快。

Stdlib or Third-Party? Empirical Performance and Correctness of LLM-Assisted Zero-Dependency Python Libraries

  • 大模型辅助生成单文件纯标准库实现,保持API兼容并强制正确性校验。
  • 多数场景性能与原库相当(差距在2倍内),部分领域提速115倍。
  • 适合关注依赖安全、部署简化或研究代码生成的开发者参考。

第三方Python库带来依赖管理开销、供应链风险和受限环境部署困难。一个自然问题是:多少生态可仅用标准库复现?代价如何?我们通过zerodep实证回答,这是一个持续扩展的单文件Python模块集合,每个都是热门第三方库的stdlib-only重实现,由大模型辅助开发,严格限制:无外部导入、单文件、可替换API、必须通过参考库的正确性验证。覆盖40多个模块、12个类别,包括序列化、网络、加密、代理协议和文本处理。系统基准测试表明,stdlib实现多数情况下性能与原库持平(差距在2倍内)。主要性能瓶颈出现在依赖C扩展的计算(如图像处理、二进制序列化、底层加密),而非纯Python库本身。相反,许多流行库存在架构冗余,而大模型生成的stdlib实现避免了这些开销,在多个类别中实现5–115倍加速。我们刻画了标准库在不同复杂度层级和类别中的能力边界,讨论了大模型辅助开发的成功场景与需人工迭代修正的领域,并探讨了大规模无依赖软件工程的启示。zerodep开源地址:https://github.com/Oaklight/zerodep。

原文摘要 · Abstract (English)

Third-party Python libraries introduce dependency management overhead, supply chain risk, and deployment friction in constrained environments. A natural question is how much of this ecosystem can be replicated using only Python's standard library -- and at what correctness and performance cost. We address this empirically through zerodep, a growing collection of single-file Python modules, each a stdlib-only reimplementation of a popular third-party library, developed with LLM assistance under strict constraints: no external imports, single file, drop-in API compatibility, and mandatory correctness validation against the reference library. Spanning over 40 modules across 12 categories -- including serialization, networking, cryptography, agent protocols, and text processing -- zerodep provides a controlled testbed for two interrelated questions: (1) Where does the stdlib suffice? and (2) Can LLMs effectively generate correct, performant code under tight symbolic constraints? Systematic benchmarking shows that stdlib-only implementations achieve performance parity (within 2x of the reference) in the majority of cases. The primary performance cliff is C-extension-backed computation (image processing, binary serialization, low-level crypto), not the inherent overhead of pure-Python third-party libraries. Conversely, many widely-used libraries carry architectural overhead that LLM-generated stdlib reimplementations avoid, yielding 5--115x speedups in several categories. We characterize the stdlib capability boundary across complexity tiers and library categories, discuss where LLM-assisted development succeeds and where it requires iterative human correction, and examine implications for dependency-free software engineering at scale. zerodep is open-source at https://github.com/Oaklight/zerodep.

代码生成标准库LLM性能优化

Thank you to arXiv for use of its open access interoperability. PaperDance 不是 arXiv 官方产品;中文卡片由大模型生成,请以原文为准。