Skip to content

Instantly share code, notes, and snippets.

@methane
Last active February 2, 2017 09:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save methane/3c34f11fb677365a7e92afe73aca24e7 to your computer and use it in GitHub Desktop.
Save methane/3c34f11fb677365a7e92afe73aca24e7 to your computer and use it in GitHub Desktop.

"app" is private application. (closed source)

default

Python 3.7.0a0 (default:ffc0840762e4+, Jan 25 2017, 20:34:30)

$ /usr/bin/time -l ../v37/bin/python3 -c 'import app; import sys; print(len(sys.modules))'
734
        1.02 real         0.94 user         0.06 sys
  52903936  maximum resident set size

=== tracemalloc stat ===
traced: (41510757, 41524477)
17,920.72KiB / count=191215
  File "<frozen importlib._bootstrap_external>", line 488
  File "<frozen importlib._bootstrap_external>", line 780

658.53KiB / count=607
  File "/Users/inada-n/work/project/v37/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 754
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/Users/inada-n/work/project/v37/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 1625
    for col in col.proxy_set:

489.99KiB / count=4116
  File "<frozen importlib._bootstrap>", line 205
  File "<frozen importlib._bootstrap_external>", line 923

399.32KiB / count=92
  File "<unknown>", line 0

316.70KiB / count=2120
  File "<frozen importlib._bootstrap>", line 205
  File "<frozen importlib._bootstrap>", line 725

302.47KiB / count=2027
  File "/Users/inada-n/local/py37/lib/python3.7/_weakrefset.py", line 84
    self.data.add(ref(item, self._remove))
  File "/Users/inada-n/local/py37/lib/python3.7/abc.py", line 230
    cls._abc_negative_cache.add(subclass)

263.02KiB / count=3524
  File "/Users/inada-n/local/py37/lib/python3.7/collections/__init__.py", line 430
    exec(class_definition, namespace)
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 1965
    nm_tpl = collections.namedtuple(name, [n for n, t in types])

modified typing.py

https://raw.githubusercontent.com/ilevkivskyi/typehinting/fefae6822300ae9900b01cbb5e9a87a67b9d98f6/src/typing.py

$ /usr/bin/time -l ../v37/bin/python3 -c 'import app; import sys; print(len(sys.modules))'
734
        1.00 real         0.92 user         0.06 sys
  52215808  maximum resident set size


traced: (41265220, 41278940)
17,922.92KiB / count=191243
  File "<frozen importlib._bootstrap_external>", line 488
  File "<frozen importlib._bootstrap_external>", line 780

658.53KiB / count=607
  File "/Users/inada-n/work/project/v37/lib/python3.7/site-packages/sqlalchemy/util/langhelpers.py", line 754
    obj.__dict__[self.__name__] = result = self.fget(obj)
  File "/Users/inada-n/work/project/v37/lib/python3.7/site-packages/sqlalchemy/orm/mapper.py", line 1625
    for col in col.proxy_set:

489.99KiB / count=4116
  File "<frozen importlib._bootstrap>", line 205
  File "<frozen importlib._bootstrap_external>", line 923

399.32KiB / count=92
  File "<unknown>", line 0

316.70KiB / count=2120
  File "<frozen importlib._bootstrap>", line 205
  File "<frozen importlib._bootstrap>", line 725

261.84KiB / count=3488
  File "/Users/inada-n/local/py37/lib/python3.7/collections/__init__.py", line 430
    exec(class_definition, namespace)
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 1991
    nm_tpl = collections.namedtuple(name, [n for n, t in types])
...
173.81KiB / count=1517
  File "/Users/inada-n/local/py37/lib/python3.7/_weakrefset.py", line 37
    self.data = set()
  File "/Users/inada-n/local/py37/lib/python3.7/abc.py", line 147
    cls._abc_negative_cache = WeakSet()
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 125
    return super().__new__(cls, name, bases, namespace)
...
125.34KiB / count=573
  File "/Users/inada-n/local/py37/lib/python3.7/_weakrefset.py", line 48
    self._iterating = set()
  File "/Users/inada-n/local/py37/lib/python3.7/abc.py", line 147
    cls._abc_negative_cache = WeakSet()
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 125
    return super().__new__(cls, name, bases, namespace)

123.44KiB / count=1193
  File "/Users/inada-n/local/py37/lib/python3.7/_weakrefset.py", line 38
    def _remove(item, selfref=ref(self)):
  File "/Users/inada-n/local/py37/lib/python3.7/abc.py", line 147
    cls._abc_negative_cache = WeakSet()
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 125
    return super().__new__(cls, name, bases, namespace)

123.23KiB / count=1034
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 696
    self = super().__new__(cls, parameters, origin, *args, _root=_root)
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 766
    return self.__class__(parameters, origin=self, _root=True)
  File "/Users/inada-n/local/py37/lib/python3.7/typing.py", line 642
    return cached(*args, **kwds)
import app
import sys
import tracemalloc
def dump_trace():
print("=== tracemalloc stat ===")
print("traced:", tracemalloc.get_traced_memory())
snapshot = tracemalloc.take_snapshot()
tracemalloc.stop()
stat = snapshot.statistics('traceback')
for s in stat[:20]:
print(f"{s.size/1024:,.2f}KiB / count={s.count}")
for l in s.traceback.format():
print(l)
print()
if tracemalloc.is_tracing():
dump_trace()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment