[Python-Dev] [ANN] superinstructions (VPython 0.1)

Antoine Pitrou solipsis at pitrou.net
Fri Oct 24 13:53:49 CEST 2008


Steve Holden <steve <at> holdenweb.com> writes:
> Though it would seem  redundant to create multiple copies of constant
> structures. Wouldn't there be some way to optimize this to allow each
> call to access the data from the same place?

It's just copying a table of pointers, so a bare memcpy() or its hand-written
equivalent is enough. Most functions shouldn't have lots of constants. Here is a
small test on some stdlib modules (with 2.5.2):

>>> def consts_per_func(mod):
...  return [len(f.func_code.co_consts) for f in vars(mod).values() if
hasattr(f, "func_code")]
... 
>>> consts_per_func(logging)
[3, 3, 2, 2, 2, 2, 3, 2, 3, 1, 3, 2, 4, 2, 3, 5, 3, 3, 1, 10, 3]
>>> consts_per_func(os)
[3, 4, 2, 4, 2, 1, 2, 1, 3, 1, 2, 2, 4, 2, 1, 2, 3, 3, 3, 3, 2, 2, 1, 1, 3, 2,
1, 1, 2, 1, 1]
>>> consts_per_func(threading)
[1, 3, 1, 1, 1, 3, 13, 1, 1, 1, 1, 1, 1, 2, 1, 1]
>>> consts_per_func(threading.Thread)
[1, 2, 1, 1, 3, 2, 2, 1, 2, 8, 2, 6, 3, 7, 13]
>>> consts_per_func(heapq)
[2, 3, 2, 2]
>>> consts_per_func(unittest.TestCase)
[2, 3, 2, 4, 2, 3, 4, 4, 3, 3, 4, 2, 3, 1, 1, 2, 1, 3, 4, 2, 2, 3, 2, 4, 2, 4,
3, 4, 2, 2, 2, 2, 4]

Regards

Antoine.




More information about the Python-Dev mailing list