Author uriyyo
Recipients Mark.Shannon, corona10, jstasiak, methane, serhiy.storchaka, uriyyo
Date 2020-11-18.09:36:46
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1605692207.54.0.0631536588787.issue42202@roundup.psfhosted.org>
In-reply-to
Content
> 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
```
History
Date User Action Args
2020-11-18 09:36:47uriyyosetrecipients: + uriyyo, methane, Mark.Shannon, serhiy.storchaka, jstasiak, corona10
2020-11-18 09:36:47uriyyosetmessageid: <1605692207.54.0.0631536588787.issue42202@roundup.psfhosted.org>
2020-11-18 09:36:47uriyyolinkissue42202 messages
2020-11-18 09:36:46uriyyocreate