diff options
author | Yurii Karabas <1998uriyyo@gmail.com> | 2020-11-25 10:43:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-25 10:43:18 (GMT) |
commit | 7301979b23406220510dd2c7934a21b41b647119 (patch) | |
tree | 296b337317ac71d34001c17f4b4b7bea918cbf6f /Python/ceval.c | |
parent | 85c84920f511d0d73a133336daeaf715a022cd64 (diff) | |
download | cpython-7301979b23406220510dd2c7934a21b41b647119.zip cpython-7301979b23406220510dd2c7934a21b41b647119.tar.gz cpython-7301979b23406220510dd2c7934a21b41b647119.tar.bz2 |
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>
Diffstat (limited to 'Python/ceval.c')
-rw-r--r-- | Python/ceval.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 3d65e16..693852e 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -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) { |