<div dir="auto">Wait. Are we talking about the C accelerator or the pure Python implementation of pickle on Python 3?<div dir="auto"><br></div><div dir="auto">Victor</div></div><div class="gmail_extra"><br><div class="gmail_quote">Le 10 juil. 2017 01:19, "INADA Naoki" <<a href="mailto:songofacandy@gmail.com">songofacandy@gmail.com</a>> a écrit :<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I don't know this is relating to your case.<br>
<br>
When I saw Victor's report [1], I researched why Python 3 is slower than<br>
Python 2 on unpickle_pure_python benchmark.<br>
<br>
[1] <a href="https://mail.python.org/pipermail/speed/2017-February/000503.html" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>pipermail/speed/2017-February/<wbr>000503.html</a><br>
<br>
<br>
And I found Python 2 and 3 uses different version of pickle format.<br>
<br>
Current Python 3 uses "framing" format. While unpickling, `read(1)` is<br>
very performance critical. Python 2 uses `cStringIO.read` which is<br>
implemented in C.<br>
On the other hand, Python 3 uses `_Unframer.read` which is implemented<br>
in Python.<br>
<br>
Since this is not relating to "first import time", I don't know this<br>
is what you want to optimize.<br>
(Since _pickle is used for normal case, pure Python unpickle<br>
performance is not a common<br>
problem).<br>
<br>
If you want to optimize it, _Unframer uses BytesIO internally and<br>
performance critical<br>
part may be able to call BytesIO.read directly instead of _Unframer.read.<br>
<br>
Regards,<br>
INADA Naoki <<a href="mailto:songofacandy@gmail.com">songofacandy@gmail.com</a>><br>
<br>
<br>
On Sun, Jul 9, 2017 at 11:08 PM, Bhavishya <<a href="mailto:bhavishyagopesh@gmail.com">bhavishyagopesh@gmail.com</a>> wrote:<br>
> Hello,<br>
><br>
> 1).I was going through the code of python pickle to search any optimization<br>
> possibility.But the only thing that I found very alarming was again the<br>
> import time(I tried with lazy-import but it didn't helped much.)<br>
><br>
> I found py3 to be ~45 times slower on initial imports(very raw<br>
> measure..using "time." ) as compared to py2 on an usual example.<br>
><br>
> py3-><br>
> ./python -c '<br>
> favorite_color = { "lion": "yellow", "kitty": "red" }<br>
> pickle.dump( favorite_color, open( "save.p", "wb" ) )'<br>
> 0.009715557098388672(time taken to do initial imports...measured using<br>
> time.time() )<br>
><br>
> py2-><br>
> ./python -c '<br>
> favorite_color = { "lion": "yellow", "kitty": "red" }<br>
> pickle.dump( favorite_color, open( "save.p", "wb" ) )'<br>
> 0.000236034393311(time taken to do initial imports...measured using<br>
> time.time() )<br>
><br>
> Do you have any thought/ideas on improving this?<br>
><br>
><br>
> Thank You.<br>
______________________________<wbr>_________________<br>
Python-Dev mailing list<br>
<a href="mailto:Python-Dev@python.org">Python-Dev@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-dev" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/listinfo/python-dev</a><br>
Unsubscribe: <a href="https://mail.python.org/mailman/options/python-dev/victor.stinner%40gmail.com" rel="noreferrer" target="_blank">https://mail.python.org/<wbr>mailman/options/python-dev/<wbr>victor.stinner%40gmail.com</a><br>
</blockquote></div></div>