This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author uriyyo
Recipients BTaskaya, methane, uriyyo
Date 2020-12-03.09:23:32
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1606987412.92.0.413267628735.issue42525@roundup.psfhosted.org>
In-reply-to
Content
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.
History
Date User Action Args
2020-12-03 09:23:32uriyyosetrecipients: + uriyyo, methane, BTaskaya
2020-12-03 09:23:32uriyyosetmessageid: <1606987412.92.0.413267628735.issue42525@roundup.psfhosted.org>
2020-12-03 09:23:32uriyyolinkissue42525 messages
2020-12-03 09:23:32uriyyocreate