Coverage analysis is widely used but can suffer from high overhead. This overhead is especially acute in the context of Python, which is already notoriously slow (a recent study observes a roughly 30x slowdown vs. native code). We find that the state-of-the-art coverage tool for Python, coverage$.$py, introduces a median overhead of 180% with the standard Python interpreter. Slowdowns are even more extreme when using PyPy, a JIT-compiled Python implementation, with coverage$.$py imposing a median overhead of 1,300%. This performance degradation reduces the utility of coverage analysis in most use cases, including testing and fuzzing, and precludes its use in deployment. This paper presents SlipCover, a novel, near-zero overhead coverage analyzer for Python. SlipCover works without modifications to either the Python interpreter or PyPy. It first processes a program's AST to accurately identify all branches and lines. SlipCover then dynamically rewrites Python bytecodes to add lightweight instrumentation to each identified branch and line. At run time, SlipCover periodically de-instruments already-covered lines and branches. The result is extremely low overheads -- a median of just 5% -- making SlipCover suitable for use in deployment. We show its efficiency can translate to significant increases in the speed of coverage-based clients. As a proof of concept, we integrate SlipCover into TPBT, a targeted property-based testing system, and observe a 22x speedup.
翻译:摘要:覆盖分析虽被广泛使用,却可能面临高额开销。这一问题在Python环境中尤为突出,因其本身已以显著低效著称(近期研究显示,相较原生代码性能衰减约30倍)。我们发现,当前Python的先进覆盖率工具coverage.py在标准Python解释器上引入的中位开销达180%。当使用即JIT编译的Python实现PyPy时,性能衰退更为极端——coverage.py导致中位开销高达1300%。这种性能劣化降低了覆盖分析在测试、模糊测试等多数场景中的实用性,并彻底阻碍其部署应用。本文提出SlipCover,一种新型近乎零开销的Python覆盖分析工具。SlipCover无需修改Python解释器或PyPy即可运行:首先处理程序抽象语法树(AST)精确识别所有分支与代码行,随后通过动态重写Python字节码为每个已识别代码单元添加轻量级插桩。运行时,SlipCover会周期性移除已被覆盖代码行的插桩。最终实现极低开销——中位仅5%——使其适用于生产环境部署。我们证明其高效性能显著加速覆盖驱动的客户端系统。作为概念验证,我们将SlipCover集成至定向属性测试系统TPBT中,观察到22倍的运行加速效果。