Issue #160: Cache minimize_source()

Before

```
python tests/bench/local.py
0 120.245933533
1 119.300842285
2 118.355035782
3 123.839855194
```

After

```
python tests/bench/local.py
0 66.3640499115
1 65.9508705139
2 72.4799633026
3 65.7958984375
```
pull/178/head
Alex Willmer 7 years ago
parent 0b46b90c62
commit 1bc32adad4

@ -44,6 +44,11 @@ import time
import types
import zlib
try:
from functools import lru_cache
except ImportError:
from mitogen.compat.functools import lru_cache
import mitogen.core
from mitogen.core import LOG
from mitogen.core import IOLOG
@ -84,6 +89,7 @@ def is_immediate_child(msg, stream):
return msg.src_id == stream.remote_id
@lru_cache()
def minimize_source(source):
"""Remove most comments and docstrings from Python source code.
"""
@ -152,6 +158,8 @@ def strip_docstrings(tokens):
def reindent(tokens, indent=' '):
"""Replace existing indentation in a token steam, with `indent`.
"""
old_levels = []
old_level = 0
new_level = 0

@ -198,6 +198,9 @@ class FindRelatedTest(testlib.TestCase):
related = self.call('mitogen.fakessh')
self.assertEquals(related, [
'mitogen',
'mitogen.compat',
'mitogen.compat.collections',
'mitogen.compat.functools',
'mitogen.core',
'mitogen.master',
'mitogen.parent',

Loading…
Cancel
Save