python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.35k stars 2.81k forks source link

Speed up TypeQuery #7128

Open JukkaL opened 5 years ago

JukkaL commented 5 years ago

mypy.type_visitor.TypeQuery is constructed often with the any or all builtin function as an argument. The function is used as a callable inside the query. Calling callable variables is kind of slow when compiled with mypyc. Since type queries are used a lot, switching to an integer constant or a compiled object instead of a callable could speed up runtimes measurably, perhaps by as much as 0.5% or so (random guess). Since the optimization is pretty simple, this may be worth doing.

Discussion:

mridullpandey commented 4 years ago

hi @JukkaL i want to work on can you assign it to me thanks :-)

mridullpandey commented 4 years ago

can you please let me know how to get started

JukkaL commented 4 years ago

@mridullpandey I've assigned this to you. Here are some hints:

vbarbaresi commented 4 years ago

I just opened a PR with my attempt at TypeQuery specialized for bool

In your first description of the issue, you wrote:

For non-bool type queries, experiment with using an object instead of a callable for the strategy, since callables are currently pretty slow when compiled.

I wanted to try that out too. You mean replacing strategy type here https://github.com/python/mypy/blob/ec76ccafa757c6d8fbb2c83195170bf75e0ff324/mypy/type_visitor.py#L257 by a new type of object that can be compiled by mypyc? There would still have to be a callable method someplace in that object, right?

Hyperion101010 commented 3 years ago

Hi there I am Shivam, I know Python to an intermediate level, I am interested to solve this issue, will you assign me?

JukkaL commented 3 years ago

@Hyperion101010 There already is an open PR here: https://github.com/python/mypy/pull/9604. However, it's not clear if it speeds things up significantly. If you want to help, you can try measuring the impact of the PR on performance. Note that if the difference is small, you may need a specialized environment, such as a machine where you've turned off turbo boost for a constant CPU frequency, and where you've disabled most background processes.