On Sat, Apr 17, 2021 at 1:38 PM Guido van Rossum <gu...@python.org> wrote: > > I'm not going to report results, but we could use mypy itself as an example > real-world code base. Mypy is almost 100% annotated. It does not include > `from __future__ import annotations` lines but those could easily be added > mechanically for some experiment. > > ISTM that the unmarshal times reported by Inada are largely proportional to > the code size numbers, so perhaps the following three-way experiment would > give an indication: > > (1) Addthe sizes of all pyc files for mypy run with Python 3.9 (classic) > (2) Ditto run with Python 3.10a7 (PEP 563) > (3) Ditto run with Larry's branch (PEP 649, assuming it's on by default there > -- otherwise, modify the source by inserting the needed future import at the > top) >
Please don't use 3.10a7, but latest master branch. CFG optimizer broke some PEP 563 optimization and I fixed it yesterday. https://github.com/python/cpython/pull/25419 > The repo is github.com/python/mypy, the subdirectory to look is mypy, WITH > THE EXCLUSION OF THE typeshed SUBDIRECTORY THEREOF. > I want to measure import time and memory usage. Will `import mypy.main` import all important modules? This is my quick result of (1) and (2). I can not try (3) because of memory error. (see later). ## memory usage ``` $ cat a.py import tracemalloc tracemalloc.start() import mypy.main print("memory:", tracemalloc.get_traced_memory()[0]) # (1) $ python3 a.py memory: 8963137 $ python3 -OO a.py memory: 8272848 # (2) $ ~/local/python-dev/bin/python3 a.py memory: 8849216 $ ~/local/python-dev/bin/python3 -OO a.py memory: 8104730 >>> (8963137-8849216)/8963137 0.012709947421310196 >>> (8272848-8104730)/8272848 0.020321659481716575 ``` PEP 563 saved 1~2% memory. ## GC time ``` $ pyperf timeit -s 'import mypy.main, gc' -- 'gc.collect()' 3.9: ..................... 2.68 ms +- 0.02 ms 3.10: ..................... 2.23 ms +- 0.01 ms Mean +- std dev: [3.9] 2.68 ms +- 0.02 ms -> [3.10] 2.23 ms +- 0.01 ms: 1.20x faster ``` PEP 563 is 1.2x faster! ## import time ``` $ python3 -m pyperf command python3 -c 'import mypy.main' (1) command: Mean +- std dev: 99.6 ms +- 0.3 ms (2) command: Mean +- std dev: 93.3 ms +- 1.2 ms >>> (99.6-93.3)/99.6 0.06325301204819275 ``` PEP 563 reduced 6% importtime. ## memory error on co_annotations I modifled py_compile to add `from __future__ import co_annotations` automatically. ``` $ ../co_annotations/python -m compileall mypy Listing 'mypy'... Compiling 'mypy/checker.py'... free(): corrupted unsorted chunks Aborted #0 __GI_raise (sig=sig@entry=6) at ../sysdeps/unix/sysv/linux/raise.c:50 #1 0x00007ffff7c73859 in __GI_abort () at abort.c:79 #2 0x00007ffff7cde3ee in __libc_message (action=action@entry=do_abort, fmt=fmt@entry=0x7ffff7e08285 "%s\n") at ../sysdeps/posix/libc_fatal.c:155 #3 0x00007ffff7ce647c in malloc_printerr (str=str@entry=0x7ffff7e0a718 "free(): corrupted unsorted chunks") at malloc.c:5347 #4 0x00007ffff7ce81c2 in _int_free (av=0x7ffff7e39b80 <main_arena>, p=0x555555d1db30, have_lock=<optimized out>) at malloc.c:4356 #5 0x0000555555603906 in PyMem_RawFree (ptr=<optimized out>) at Objects/obmalloc.c:1922 #6 _PyObject_Free (ctx=<optimized out>, p=<optimized out>) at Objects/obmalloc.c:1922 #7 _PyObject_Free (ctx=<optimized out>, p=<optimized out>) at Objects/obmalloc.c:1913 #8 0x000055555567caa9 in compiler_unit_free (u=0x555555ef0fd0) at Python/compile.c:583 #9 0x000055555568aea5 in compiler_exit_scope (c=0x7fffffffc3d0) at Python/compile.c:760 #10 compiler_function (c=0x7fffffffc3d0, s=<optimized out>, is_async=0) at Python/compile.c:2529 #11 0x000055555568837d in compiler_visit_stmt (s=<optimized out>, c=0x7fffffffc3d0) at Python/compile.c:3665 #12 compiler_body (c=c@entry=0x7fffffffc3d0, stmts=0x555556222450) at Python/compile.c:1977 #13 0x0000555555688e51 in compiler_class (c=c@entry=0x7fffffffc3d0, s=s@entry=0x555556222a60) at Python/compile.c:2623 #14 0x0000555555687ce3 in compiler_visit_stmt (s=<optimized out>, c=0x7fffffffc3d0) at Python/compile.c:3667 #15 compiler_body (c=c@entry=0x7fffffffc3d0, stmts=0x5555563014c0) at Python/compile.c:1977 #16 0x000055555568db00 in compiler_mod (filename=0x7ffff72e6770, mod=0x5555563017b0, c=0x7fffffffc3d0) at Python/compile.c:2001 ``` -- Inada Naoki <songofaca...@gmail.com> _______________________________________________ Python-Dev mailing list -- python-dev@python.org To unsubscribe send an email to python-dev-le...@python.org https://mail.python.org/mailman3/lists/python-dev.python.org/ Message archived at https://mail.python.org/archives/list/python-dev@python.org/message/2UON4FZ5UJ3RYE3ZO5Q445RVPMFAR2SW/ Code of Conduct: http://python.org/psf/codeofconduct/