Yurii Karabas <1998uri...@gmail.com> added the comment:
> func.__annotations__ = ('x', 'int', 'z', 'float', 'return', 'Hoge') is much > better because: Inada, I totally agree with you. Sorry, I didn't realize all pitfalls with extra field to codeobject. New implementation with annotations representation as a single tuple doesn't require a lot to change to the existing codebase. And I have already done it. I rerun all benchmarks and there is no performance degradation in a case when the function doesn't have annotations and it's more than 2 times faster when the function has annotations. Benchmark results: ``` def f(x: int, /, y, *, z: float) -> int: pass Python 3.8.3 5000000 loops, best of 5: 209 nsec per loop Python 3.9.0 5000000 loops, best of 5: 232 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 138 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 56.1 nsec per loop def f(a: int, /, b: int, *, c: int) -> None: pass Python 3.8.3 5000000 loops, best of 5: 241 nsec per loop Python 3.9.0 5000000 loops, best of 5: 274 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 158 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 58.8 nsec per loop def f(a: int, /, b: int, *, c: int, **d: int) -> None: pass Python 3.8.3 5000000 loops, best of 5: 256 nsec per loop Python 3.9.0 5000000 loops, best of 5: 326 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 264 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 87.1 nsec per loop def f(a: int, b: str) -> None: pass Python 3.6.8 5000000 loops, best of 3: 0.215 usec per loop Python 3.7.6 5000000 loops, best of 5: 201 nsec per loop Python 3.8.3 5000000 loops, best of 5: 204 nsec per loop Python 3.9.0 5000000 loops, best of 5: 204 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 137 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 55.8 nsec per loop def f(a: int, *, b: int) -> None: pass Python 3.6.8 5000000 loops, best of 3: 0.186 usec per loop Python 3.7.6 5000000 loops, best of 5: 181 nsec per loop Python 3.8.3 5000000 loops, best of 5: 166 nsec per loop Python 3.9.0 5000000 loops, best of 5: 189 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 138 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 64.7 nsec per loop def f(a, /, b, *, c) -> None: pass Python 3.8.3 5000000 loops, best of 5: 96 nsec per loop Python 3.9.0 5000000 loops, best of 5: 102 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 98.7 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 57.4 nsec per loop def f(a, /, b, *, c, **d) -> None: pass Python 3.8.3 5000000 loops, best of 5: 97.8 nsec per loop Python 3.9.0 5000000 loops, best of 5: 105 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 96.8 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 58.3 nsec per loop def f(a, b) -> None: pass Python 3.6.8 5000000 loops, best of 3: 0.107 usec per loop Python 3.7.6 5000000 loops, best of 5: 99.7 nsec per loop Python 3.8.3 5000000 loops, best of 5: 97.5 nsec per loop Python 3.9.0 5000000 loops, best of 5: 103 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 100 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 57.5 nsec per loop def f(a, *, b) -> None: pass Python 3.6.8 5000000 loops, best of 3: 0.105 usec per loop Python 3.7.6 5000000 loops, best of 5: 99.4 nsec per loop Python 3.8.3 5000000 loops, best of 5: 95.5 nsec per loop Python 3.9.0 5000000 loops, best of 5: 103 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 94.9 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 59.2 nsec per loop def f(): pass Python 3.6.8 5000000 loops, best of 3: 0.0542 usec per loop Python 3.7.6 5000000 loops, best of 5: 51.2 nsec per loop Python 3.8.3 5000000 loops, best of 5: 52.3 nsec per loop Python 3.9.0 5000000 loops, best of 5: 52.1 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 60.8 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 59.8 nsec per loop def f(a, /, b, *, c): pass Python 3.8.3 5000000 loops, best of 5: 56.1 nsec per loop Python 3.9.0 5000000 loops, best of 5: 59.8 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 64 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 60.6 nsec per loop def f(a, /, b, *, c, **d): pass Python 3.8.3 5000000 loops, best of 5: 53.6 nsec per loop Python 3.9.0 5000000 loops, best of 5: 50.7 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 54.1 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 53.9 nsec per loop def f(a, b): pass Python 3.6.8 5000000 loops, best of 3: 0.054 usec per loop Python 3.7.6 5000000 loops, best of 5: 53.9 nsec per loop Python 3.8.3 5000000 loops, best of 5: 54.1 nsec per loop Python 3.9.0 5000000 loops, best of 5: 52.5 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 53.7 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 53.8 nsec per loop def f(a, *, b): pass Python 3.6.8 5000000 loops, best of 3: 0.0528 usec per loop Python 3.7.6 5000000 loops, best of 5: 51.2 nsec per loop Python 3.8.3 5000000 loops, best of 5: 51.4 nsec per loop Python 3.9.0 5000000 loops, best of 5: 52.4 nsec per loop Python 3.10.0a2+ 5000000 loops, best of 5: 55.7 nsec per loop Python 3.10.0a2+ with compact representation 5000000 loops, best of 5: 53.7 nsec per loop ``` ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue42202> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com