Message148627
Pickling of bytearrays is quite inefficient right now, because bytearray's __reduce__ encodes the bytes of the bytearray into a str. A pickle made from a bytearray is quite a bit larger than necessary because of this, and it also takes a lot more processing to create it and to convert it back into the actual bytearray when unpickling (because it uses bytearray's str based initializer with encoding).
I've attached a patch (both for the default 3.x branch and the 2.7 branch) that changes this to use the bytes type instead. A pickle made from a bytearray with this patch applied now utilizes the BINBYTES/BINSTRING pickle opcodes which are a lot more efficient than BINUNICODE that is used now. The reconstruction of the bytearray now uses bytearray's initializer that takes a bytes object.
I don't think additional unit tests are needed because test_bytes already performs pickle tests on bytearrays.
A bit more info can be found in my recent post on comp.lang.python about this, see http://mail.python.org/pipermail/python-list/2011-November/1283668.html |
|
Date |
User |
Action |
Args |
2011-11-30 00:09:16 | irmen | set | recipients:
+ irmen, pitrou, alexandre.vassalotti |
2011-11-30 00:09:16 | irmen | set | messageid: <1322611756.83.0.989666994675.issue13503@psf.upfronthosting.co.za> |
2011-11-30 00:09:16 | irmen | link | issue13503 messages |
2011-11-30 00:09:15 | irmen | create | |
|