summaryrefslogtreecommitdiff
path: root/coverage/collector.py
diff options
context:
space:
mode:
authorAlex Gaynor <alex.gaynor@gmail.com>2014-09-22 22:30:55 +0000
committerAlex Gaynor <alex.gaynor@gmail.com>2014-09-22 22:30:55 +0000
commitc466bad3369f48a4955621a06c8b6ef096c50f91 (patch)
tree44b795224172a93350cab9136c119ab1f6ec482b /coverage/collector.py
parentd68b95f7a0a201b2e8e830b6d4769005ef0223fa (diff)
downloadpython-coveragepy-git-c466bad3369f48a4955621a06c8b6ef096c50f91.tar.gz
Improve performance of coverage under PyPy.
An explanation is in order: should_trace_cache is a strictly growing key, which is to say once a key is in it, it never changes. Further, the keys used to access it are generally constant, given sufficient context. That is to say, at any given point _trace() is called, a Sufficient Smart Compiler (tm) is able to know the key. This is because the key is determined by the physical source code line, and that's obviously invariant with the call site. This property of a dict with immutable keys, combined call-site-constant keys is a match for PyPy's module dict, which is optimized for such workloads. This gives a 20% benefit on the workload described at https://bitbucket.org/pypy/pypy/issue/1871/10x-slower-than-cpython-under-coverage I have not benchmarked on a wider array of programs yet. --HG-- branch : alex_gaynor/improve-performance-of-coverage-under-py-1411425050845
Diffstat (limited to 'coverage/collector.py')
-rw-r--r--coverage/collector.py10
1 files changed, 9 insertions, 1 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index 85c8dc90..c571cb06 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -23,6 +23,11 @@ except ImportError:
sys.exit(1)
CTracer = None
+try:
+ import __pypy__
+except ImportError:
+ __pypy__ = None
+
class Collector(object):
"""Collects trace data.
@@ -134,7 +139,10 @@ class Collector(object):
# A cache of the results from should_trace, the decision about whether
# to trace execution in a file. A dict of filename to (filename or
# None).
- self.should_trace_cache = {}
+ if __pypy__ is not None:
+ self.should_trace_cache = __pypy__.newdict("module")
+ else:
+ self.should_trace_cache = {}
# Our active Tracers.
self.tracers = []