Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
skip to main content
10.1145/3597926.3598128acmconferencesArticle/Chapter ViewAbstractPublication PagesisstaConference Proceedingsconference-collections
research-article
Public Access

SlipCover: Near Zero-Overhead Code Coverage for Python

Published: 13 July 2023 Publication History

Abstract

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.

References

[1]
Ned Batchelder. 2023. nedbat/coveragepy: The code coverage tool for Python. https://github.com/nedbat/coveragepy
[2]
Bryan Roger Buck and Jeffrey K. Hollingsworth. 2000. An API for Runtime Code Patching. Int. J. High Perform. Comput. Appl., 14, 4 (2000), 317–329. https://doi.org/10.1177/109434200001400404
[3]
Kalyan-Ram Chilakamarri and Sebastian G. Elbaum. 2006. Leveraging disposable instrumentation to reduce coverage collection overhead. Softw. Test. Verification Reliab., 16, 4 (2006), 267–288. https://doi.org/10.1002/stvr.347
[4]
2023. Python downloads. https://www.python.org/downloads/
[5]
Liam DeVoe and Leonidas Lampropoulos. 2023. Generalized Targeted Property-Based Testing in Python. Unpublished manuscript.
[6]
David Lord et al. 2023. Flask, a lightweight web application framework. https://github.com/pallets/flask
[7]
2023. “Faster CPython” section in Python 3.11 documentation. https://docs.python.org/3/whatsnew/3.11.html#whatsnew311-faster-cpython
[8]
Marko Ivanković, Goran Petrović, René Just, and Gordon Fraser. 2019. Code coverage at Google. In Proceedings of the ACM Joint Meeting on European Software Engineering Conference and Symposium on the Foundations of Software Engineering, ESEC/SIGSOFT FSE 2019, Tallinn, Estonia, August 26-30, 2019, Marlon Dumas, Dietmar Pfahl, Sven Apel, and Alessandra Russo (Eds.). ACM, 955–963. https://doi.org/10.1145/3338906.3340459
[9]
2023. JaCoCo Java Code Coverage Library. https://jacoco.org
[10]
2023. Java instrumentation API. https://docs.oracle.com/javase/7/docs/api/java/lang/instrument/Instrumentation.html
[11]
Nan Li, Xin Meng, Jeff Offutt, and Lin Deng. 2013. Is bytecode instrumentation as good as source code instrumentation: An empirical study with industrial tools (Experience Report). In IEEE 24th International Symposium on Software Reliability Engineering, ISSRE 2013, Pasadena, CA, USA, November 4-7, 2013. IEEE Computer Society, 380–389. https://doi.org/10.1109/ISSRE.2013.6698891
[12]
Tim Lindholm, Frank Yellin, Gilad Bracha, and Alex Buckley. 2013. The Java Virtual Machine Specification. https://docs.oracle.com/javase/specs/jvms/se7/html/jvms-4.html
[13]
David Lion, Adrian Chiu, Michael Stumm, and Ding Yuan. 2022. Investigating Managed Language Runtime Performance: Why JavaScript and Python are 8x and 29x slower than C++, yet Java and Go can be Faster? In 2022 USENIX Annual Technical Conference, USENIX ATC 2022, Carlsbad, CA, USA, July 11-13, 2022, Jiri Schindler and Noa Zilberman (Eds.). USENIX Association, 835–852. https://www.usenix.org/conference/atc22/presentation/lion
[14]
J. Misurda, J.A. Clause, J.L. Reed, B.R. Childers, and M.L. Soffa. 2005. Demand-driven structural testing with dynamic instrumentation. In Proceedings. 27th International Conference on Software Engineering, 2005. ICSE 2005. 156–165. https://doi.org/10.1109/ICSE.2005.1553558
[15]
Stefan Nagy and Matthew Hicks. 2019. Full-Speed Fuzzing: Reducing Fuzzing Overhead through Coverage-Guided Tracing. In 2019 IEEE Symposium on Security and Privacy, SP 2019, San Francisco, CA, USA, May 19-23, 2019. IEEE, 787–802. https://doi.org/10.1109/SP.2019.00069
[16]
Peter Norvig. 2010. Solving Every Sudoku Puzzle. http://norvig.com/sudoku.html
[17]
Christina Pavlopoulou and Michal Young. 1999. Residual test coverage monitoring. In Proceedings of the 21st international conference on Software engineering. 277–284. https://doi.org/10.1145/302405.302637
[18]
F. Pedregosa, G. Varoquaux, A. Gramfort, V. Michel, B. Thirion, O. Grisel, M. Blondel, P. Prettenhofer, R. Weiss, V. Dubourg, J. Vanderplas, A. Passos, D. Cournapeau, M. Brucher, M. Perrot, and E. Duchesnay. 2011. Scikit-learn: Machine Learning in Python. Journal of Machine Learning Research, 12 (2011), 2825–2830.
[19]
2023. PyPY, a fast, compliant alternative implementation of Python. https://pypy.org
[20]
2022. CPython GitHub issue: severe performance degradation for tracing under 3.11. https://github.com/python/cpython/issues/93516
[21]
2023. Python Profiling and Tracing API. https://docs.python.org/3/c-api/init.html#profiling-and-tracing
[22]
2023. The match statement. https://docs.python.org/3.10/reference/compound_stmts.html#the-match-statement
[23]
Mark Shannon. 2021. PEP659: Specializing Adaptive Interpreter. https://peps.python.org/pep-0659
[24]
2023. The Python Benchmark Suite. https://github.com/python/pyperformance
[25]
Mustafa M. Tikir and Jeffrey K. Hollingsworth. 2005. Efficient online computation of statement coverage. J. Syst. Softw., 78, 2 (2005), 146–165. https://doi.org/10.1016/j.jss.2004.12.021

Cited By

View all

Recommendations

Comments

Information & Contributors

Information

Published In

cover image ACM Conferences
ISSTA 2023: Proceedings of the 32nd ACM SIGSOFT International Symposium on Software Testing and Analysis
July 2023
1554 pages
ISBN:9798400702211
DOI:10.1145/3597926
Permission to make digital or hard copies of all or part of this work for personal or classroom use is granted without fee provided that copies are not made or distributed for profit or commercial advantage and that copies bear this notice and the full citation on the first page. Copyrights for components of this work owned by others than the author(s) must be honored. Abstracting with credit is permitted. To copy otherwise, or republish, to post on servers or to redistribute to lists, requires prior specific permission and/or a fee. Request permissions from [email protected].

Sponsors

Publisher

Association for Computing Machinery

New York, NY, United States

Publication History

Published: 13 July 2023

Permissions

Request permissions for this article.

Check for updates

Author Tags

  1. Code Coverage
  2. Dynamic Code Instrumentation
  3. Python
  4. Testing

Qualifiers

  • Research-article

Funding Sources

Conference

ISSTA '23
Sponsor:

Acceptance Rates

Overall Acceptance Rate 58 of 213 submissions, 27%

Upcoming Conference

ISSTA '25

Contributors

Other Metrics

Bibliometrics & Citations

Bibliometrics

Article Metrics

  • 0
    Total Citations
  • 182
    Total Downloads
  • Downloads (Last 12 months)110
  • Downloads (Last 6 weeks)16
Reflects downloads up to 09 Jan 2025

Other Metrics

Citations

Cited By

View all

View Options

View options

PDF

View or Download as a PDF file.

PDF

eReader

View online with eReader.

eReader

Login options

Media

Figures

Other

Tables

Share

Share

Share this Publication link

Share on social media