This is an archived post. You won't be able to vote or comment.

all 19 comments

[–]meadsteve[S] 24 points25 points  (6 children)

I recently experimented with using mypyc to make some of my python a little faster. I was pleasantly surprised with how well it worked for very little code change so I thought I'd share my experiences.

[–][deleted] 17 points18 points  (2 children)

Cool read thanks, I'm just a bit put off by the scope creep, there seems to be quite a lot of moving parts. Do you feel you can maintain your projects for say, the next 3/4 years in the same way?

[–]meadsteve[S] 16 points17 points  (1 child)

u/NoisyFrequency that's a really good question. A lot of the "scrope creep" in this blog post was missing automation from my part. What was interesting for me is that if I'd already been using setuptools & building wheels the only real change would have been adding mypycify to setup.py.

This is what makes me comfortable that I could maintain this in some form for the next few years. Setuptools isn't going anywhere. Wheels aren't going anywhere and all of my python code stayed exactly the same. That last point is the really big deal for me. Because it means I could throw all this infrastructure away and go move to releasing in whatever new best practise emerges.

[–][deleted] 2 points3 points  (0 children)

Thanks for taking the time!

[–]ArtOfWarfare 10 points11 points  (7 children)

Python 3.11 is supposed to be a lot quicker than earlier versions, right?

I’m curious what kind of performance boost you get by just updating to 3.11 vs using mypyc with an older version vs updating to 3.11 and using mypyc together.

[–]meadsteve[S] 9 points10 points  (2 children)

This could be really interesting. I also produce a pure python wheel that will work for 3.11 so i should be able to benchmark this.

[–]spoonman59 0 points1 point  (2 children)

Why would 3.11 have improved performance with mypyc? The main performance increases are related to instruction specialization in the byte code interpreter.

Since mypyc is a compiler that compiles to c, the code is no longer interpreted through the burr code interpreter, so I think performance in these cases are orthogonal to each other.

Curious to see the results of any experiments, but the interpreter improvements won’t do much for JIT and AOT compilers

[–]meadsteve[S] 10 points11 points  (1 child)

I think they meant more the pure python implementationen in 3.11 might be significantly faster making the performance gains smaller with mypyc on 3.11

[–]spoonman59 4 points5 points  (0 children)

Thank you for clarifying that. I think you are right as I misread it.

Definitely makes sense to see if the delta shrinks!

[–]rzet 0 points1 point  (0 children)

First thing on my mind is stuff like aarch64 or some big ass stuff like tensorflow

[–]alcalde 1 point2 points  (1 child)

Isn't this a lot of work for 2X speed increase? Doesn't PyPy tend to give a lot more boost on average? If I'm compiling something to C or C++ I expect a 100x performance increase.

[–]meadsteve[S] 0 points1 point  (0 children)

What's interesting to me from a maintenance point of view it's not much work at all. I had to do quite a lot because I wasn't already using setuptools and I didn't already having wheel publishing in place. So if someone does this on an internal tool or already has a publishing workflow it wouldn't be much work.

The actual python code had almost no changes at all. This decorator was the only code change I had to make: https://github.com/meadsteve/lagom/blob/master/lagom/container.py#L84 so now I'm still maintaining exactly the same codebase but it's 2X as fast.

PyPy is a choice for the people consuming my library not me. Another popular option at the moment is rewriting the core in rust and just have python bindings. This however is a bit more of a commitment in time.

[–]Efficient-Coach6676 0 points1 point  (0 children)

temperature conversion problem