Yurii Karabas <[email protected]> added the comment:
As all annotations are known at compilation time we can optimize annotations
creating.
For instance, we have such code:
```
a: int
b: int
```
With the current implementation, we will have such bytecode:
```
1 0 SETUP_ANNOTATIONS
2 LOAD_CONST 0 ('int')
4 LOAD_NAME 0 (__annotations__)
6 LOAD_CONST 1 ('a')
8 STORE_SUBSCR
2 10 LOAD_CONST 0 ('int')
12 LOAD_NAME 0 (__annotations__)
14 LOAD_CONST 2 ('b')
16 STORE_SUBSCR
18 LOAD_CONST 3 (None)
20 RETURN_VALUE
```
I would suggest using `BUILD_CONST_KEY_MAP` and bytecode will look like this:
```
2 0 LOAD_CONST 0 ('int')
3 2 LOAD_CONST 0 ('int')
1 4 LOAD_CONST 1 (('a', 'b'))
6 BUILD_CONST_KEY_MAP 2
8 SETUP_ANNOTATIONS
10 LOAD_CONST 2 (None)
12 RETURN_VALUE
```
So `SETUP_ANNOTATIONS` bytecode will accept a dictionary with annotations of a
current module/class.
I will look more like micro-optimization, I can implement this feature and run
benchmarks to check performance boost.
I believe this optimization won't require a lot to change.
----------
_______________________________________
Python tracker <[email protected]>
<https://bugs.python.org/issue42525>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com