summaryrefslogtreecommitdiff
path: root/coverage/collector.py
diff options
context:
space:
mode:
authorNed Batchelder <ned@nedbatchelder.com>2014-10-01 07:47:05 -0400
committerNed Batchelder <ned@nedbatchelder.com>2014-10-01 07:47:05 -0400
commita76f2e56d64b1fb245c435317c1f259c7e5dd0d8 (patch)
tree48b363af185b05f2577a75e6504ec44db5c103f1 /coverage/collector.py
parent9af6bd3df6db9288199b2dbf9e243d14e6dc6e01 (diff)
downloadpython-coveragepy-a76f2e56d64b1fb245c435317c1f259c7e5dd0d8.tar.gz
Add comment and cleanups to Alex's PyPy change.
Diffstat (limited to 'coverage/collector.py')
-rw-r--r--coverage/collector.py16
1 files changed, 15 insertions, 1 deletions
diff --git a/coverage/collector.py b/coverage/collector.py
index 66de8b6..001bc3d 100644
--- a/coverage/collector.py
+++ b/coverage/collector.py
@@ -24,7 +24,7 @@ except ImportError:
CTracer = None
try:
- import __pypy__
+ import __pypy__ # pylint: disable=import-error
except ImportError:
__pypy__ = None
@@ -142,6 +142,20 @@ class Collector(object):
# to trace execution in a file. A dict of filename to (filename or
# None).
if __pypy__ is not None:
+ # Alex Gaynor said:
+ # should_trace_cache is a strictly growing key: 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, pypy is able to know the key.
+ # This is because the key is determined by the physical source code
+ # line, and that's invariant with the call site.
+ #
+ # This property of a dict with immutable keys, combined with
+ # 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
self.should_trace_cache = __pypy__.newdict("module")
else:
self.should_trace_cache = {}