This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author irmen
Recipients alexandre.vassalotti, irmen, pitrou
Date 2011-11-30.00:09:15
SpamBayes Score 3.3971183e-08
Marked as misclassified No
Message-id <1322611756.83.0.989666994675.issue13503@psf.upfronthosting.co.za>
In-reply-to
Content
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
History
Date User Action Args
2011-11-30 00:09:16irmensetrecipients: + irmen, pitrou, alexandre.vassalotti
2011-11-30 00:09:16irmensetmessageid: <1322611756.83.0.989666994675.issue13503@psf.upfronthosting.co.za>
2011-11-30 00:09:16irmenlinkissue13503 messages
2011-11-30 00:09:15irmencreate