Message256322
One of purposes of the STACK_GLOBAL opcode introduced in pickle protocol 4 is to avoid repeating module name for different globals of the same module.
>>> pickletools.dis(pickletools.optimize(pickle.dumps([sys.getsizeof, sys.intern], 4)))
0: \x80 PROTO 4
2: \x95 FRAME 33
11: ] EMPTY_LIST
12: ( MARK
13: \x8c SHORT_BINUNICODE 'sys'
18: \x94 MEMOIZE (as 0)
19: \x8c SHORT_BINUNICODE 'getsizeof'
30: \x93 STACK_GLOBAL
31: h BINGET 0
33: \x8c SHORT_BINUNICODE 'intern'
41: \x93 STACK_GLOBAL
42: e APPENDS (MARK at 12)
43: . STOP
highest protocol among opcodes = 4
But this doesn't work with the itertools module.
>>> pickletools.dis(pickletools.optimize(pickle.dumps([itertools.chain, itertools.accumulate], 4)))
0: \x80 PROTO 4
2: \x95 FRAME 47
11: ] EMPTY_LIST
12: ( MARK
13: \x8c SHORT_BINUNICODE 'itertools'
24: \x8c SHORT_BINUNICODE 'chain'
31: \x93 STACK_GLOBAL
32: \x8c SHORT_BINUNICODE 'itertools'
43: \x8c SHORT_BINUNICODE 'accumulate'
55: \x93 STACK_GLOBAL
56: e APPENDS (MARK at 12)
57: . STOP
highest protocol among opcodes = 4
That is because the __module__ attribute of itertools members is not interned.
>>> sys.getsizeof.__module__ is sys.intern.__module__
True
>>> itertools.chain.__module__ is itertools.chain.__module__
False
In addition to inefficient pickle this perhaps leads to small performance hit on accessing the __module__ attribute or using its value as dictionary key. |
|
Date |
User |
Action |
Args |
2015-12-13 16:17:44 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, pitrou, alexandre.vassalotti |
2015-12-13 16:17:44 | serhiy.storchaka | set | messageid: <1450023464.36.0.165437491365.issue25856@psf.upfronthosting.co.za> |
2015-12-13 16:17:44 | serhiy.storchaka | link | issue25856 messages |
2015-12-13 16:17:42 | serhiy.storchaka | create | |
|