使用 Python 3.15 对 web-edit 进行性能分析:火焰图和源代码热力图

Simon Willison's Blog 新闻

摘要

Simon Willison 使用 Python 3.15 内置的采样分析器,对他的新应用 web-edit 进行性能分析,发现保留混合换行符占用了大部分 CPU 时间,并演示了如何使用这些新工具生成火焰图和源代码热力图。

暂无内容
查看原文
查看缓存全文

缓存时间: 2026/10/13 22:48

# 研究:使用 Python 3.15 对 web-edit 进行性能分析:火焰图和源码热力图 来源:https://simonwillison.net/2026/Oct/12/python-3-15-web-edit-profiling/ 研究 (https://simonwillison.net/elsewhere/research/)使用 Python 3\.15 对 web\-edit 进行性能分析:火焰图和源码热力图 (https://github.com/simonw/research/tree/main/python-3-15-web-edit-profiling#readme)—— 使用 Python 3\.15 内置的 \`profiling\.sampling\` 对未经修改的 web\-edit 应用进行性能分析后发现,在繁忙的编辑工作负载中,保留混合换行符占据了大部分开销:在记录的 15,296 个 CPU 调用栈中,\`preserve\_endings\` 出现在 64\.8% 的调用栈中,而 \`SequenceMatcher\.find\_longest\_match\` 占叶节点样本的 38\.3%。对所有线程进行采样至关重要,因为 95\.1% 的调用栈来自 AnyIO 的工作线程,仅分析主线程会漏掉这些调用栈。 我让 Codex 中的 GPT\-6 Astra Extra High 使用全新的 Python 3\.15 性能分析器 (https://simonwillison.net/2026/Oct/12/python-3-15/#a-sampling-profiler)对我新开发的 web\-edit 应用 (https://simonwillison.net/2026/Oct/12/web-edit/)进行分析,以此全面测试这个分析器: > `我需要一个使用 Python 3\.15 对 PyPI 上的「web\-edit」应用生成火焰图和热力图的演示 \- 先做研究,然后为我制作这些演示` 以下是生成的示例火焰图 (https://simonw.github.io/research/python-3-15-web-edit-profiling/artifacts/flamegraph.html)和热力图 (https://simonw.github.io/research/python-3-15-web-edit-profiling/artifacts/heatmap/index.html)。

相似文章

Profiling.sampling – 统计性性能剖析器

Hacker News Top

Python 3.15 引入了 profiling.sampling 模块,即 Tachyon,一种统计性性能剖析器,它会定期采样堆栈快照,开销极小,适用于开发和生产环境。