mirror of
https://github.com/python/cpython.git
synced 2025-10-06 23:21:06 +00:00
bpo-42202: Store func annotations as a tuple (GH-23316)
Reduce memory footprint and improve performance of loading modules having many func annotations. >>> sys.getsizeof({"a":"int","b":"int","return":"int"}) 232 >>> sys.getsizeof(("a","int","b","int","return","int")) 88 The tuple is converted into dict on the fly when `func.__annotations__` is accessed first. Co-authored-by: Serhiy Storchaka <storchaka@gmail.com> Co-authored-by: Inada Naoki <songofacandy@gmail.com>
This commit is contained in:
parent
85c84920f5
commit
7301979b23
8 changed files with 174 additions and 155 deletions
|
@ -3880,7 +3880,7 @@ main_loop:
|
|||
func ->func_closure = POP();
|
||||
}
|
||||
if (oparg & 0x04) {
|
||||
assert(PyDict_CheckExact(TOP()));
|
||||
assert(PyTuple_CheckExact(TOP()));
|
||||
func->func_annotations = POP();
|
||||
}
|
||||
if (oparg & 0x02) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue