一句话:SlipCover 通过 AST 识别与字节码动态插桩/去插桩,将 Python 覆盖率开销降至中位数 5%。
覆盖率分析常因高开销而受限,Python 中尤为严重:标准解释器下 coverage.py 中位开销 180%,PyPy 下高达 1300%,限制了测试、模糊测试和部署场景。SlipCover 无需修改 Python 解释器或 PyPy:先分析 AST 精确识别分支与行,再动态重写字节码,为每个分支和行加入轻量插桩;运行时周期性移除已覆盖的行和分支的插桩。评估显示其开销中位数仅 5%,可用于部署。作者还将 SlipCover 集成到定向属性测试系统 TPBT,获得 22 倍加速。
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.