[Python-ideas] Length hinting and preallocation for container types
Antoine Pitrou
solipsis at pitrou.net
Thu Mar 7 11:28:17 CET 2013
Le Wed, 06 Mar 2013 11:23:26 +0900,
"Stephen J. Turnbull" <stephen at xemacs.org>
a écrit :
>
> Not at all coincidentally. As a compiler writer (which he refers to
> in the slides several times) he is offended by poor performance, as
> measured in CPU/invocation. Good for him! I'm glad he's working on
> PyPy! But when compiler writers start talking language design for
> performance, we inevitably end up with C<0.5 wink/>.
I think that's a strong argument indeed.
> > > One of his assertions is about memory (re)allocation. C is faster
> > > in some cases because C code usually does fewer allocations and
> > > reallocations. Python has no API to easily reallocate a list with
> > > 100 items.
>
> And it shouldn't.<wink/>
>
> But why do you think allocation is slow in the general case? Sure, it
> involves system calls which indeed do slow things down.
It depends what one calls a system call. A memory allocation shouldn't
always incur a call to the kernel. Library calls can be quite fast.
Moreover, in the CPython case, there's also a custom allocator which
handles all allocation requests smaller than 512 bytes.
(I'm sure PyPy has their own allocator too)
Regards
Antoine.
More information about the Python-ideas
mailing list