[Python-ideas] Type Hinting - Performance booster ?

Nick Coghlan ncoghlan at gmail.com
Sun Dec 21 02:15:17 CET 2014


On 21 December 2014 at 09:55, Ludovic Gasc <gmludo at gmail.com> wrote:

> Hi,
>
> I'm only a simple Python developer, not a Type Hinting expert and I don't
> know if you already discuss about that somewhere, but:
>
> With the future official support of Type Hinting in Python, is it means
> that CPython could use this pieces of information to store variables with
> more efficient data structures, not only check types ?
>
> It could possible to have better performance one day with Type Hinting
> like you have with Cython (explicit types declaration) or PyPy (guessing
> types) ?
>

The primary goals of the type hinting standardisation effort are improving
program correctness (through enhanced static analysis) and API
documentation (through clearer communication of expectations for input and
output, both in the code, in documentation, and in IDEs). It should also
allow the development of more advanced techniques for function signature
based dispatch and other forms of structured pattern matching.

>From a performance perspective though, CPython already has a wide array of
fast paths for particular builtin types - being able to communicate those
assumptions more clearly won't automatically make it easier to speed them
up further (or add more in a maintainable fashion). There's no
*philosophical* objection to such changes (other than "simplicity is a
virtue"), there's just a long track record of previous attempts like psyco
and Unladen Swallow that make it clear that the problem is genuinely *hard*.

There's also the fact that with both Numba and PyPy now supporting
selective JIT acceleration of decorated functions within the context of a
larger CPython application, as well as Cython's existing support for
precompilation as a C extension, the pattern of profiling to find
performance critical areas, and finding ways to optimise those, now seems
well established. (Hence my suggestion the other day that we could likely
use an introductory how to guide on performance profiling, which could also
provide suggestions for optimisation tools to explore once the hot spots
have been found).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20141221/83cc6513/attachment.html>


More information about the Python-ideas mailing list