pypy / pypy.org

Sources for website at https://www.pypy.org
33 stars 11 forks source link

Idea: blog post on andythenorth's pypy use #43

Open cfbolz opened 2 years ago

cfbolz commented 2 years ago

so it doesn't get lost, here is the discussion from IRC:

andythenorth> Textual User morning (EU TZ)
10:18:53 picking up a chat from mailing list...
10:19:22 I am using pypy3 on m1 mac; I'm not a programmer but I use pypy to compile game mods
10:19:56 I've compiled on m1 with x86, and it's roughly same performance as on intel i9 mac, some things faster, some slower
10:20:39 I can contribute funds directly towards an m1 for a pypy3 dev, not the whole price of a mac mini or macbook air
10:21:20 but I spend hundreds of hours per year of hobby time on these mods, and saving 4 or 5 seconds on compiling really improves cycle time
10:21:57 I could easily put in 1/3 of the cost of a mac mini at UK prices 
10:22:11 and it would be nice to support a very valuable open source project
10:23:45 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: hey :-)
10:23:55 
<andythenorth> Textual User hi
10:24:03 
<cfbolz> Carl Friedrich Bolz-Tereick we have a mac mini available and ordered a laptop
10:24:09 
<andythenorth> Textual User excellent
10:24:12 need any funds?
10:24:36 
<cfbolz> Carl Friedrich Bolz-Tereick a small donation here is appreciated: https://opencollective.com/pypy
10:24:50 
<andythenorth> Textual User happy to do that
10:24:52 
<cfbolz> Carl Friedrich Bolz-Tereick but something else you could do, that would actually be extremely valuable: wanna write a blog post?
10:25:01 just write a bit how you're using pypy
10:25:02 
<andythenorth> Textual User now you ask the hard questions :D
10:25:05 
<cfbolz> Carl Friedrich Bolz-Tereick hehe
10:25:47 andythenorth: it's not urgent or anything, just think about it :-)
10:25:57 
<andythenorth> Textual User I will put a couple of lines of background here, to give me some ideas
10:26:14 
<cfbolz> Carl Friedrich Bolz-Tereick please!
10:26:20 (we're really interested anyway ;-) )
10:26:33 
<andythenorth> Textual User I'm a contrib to OpenTTD, which, not talking ourselves up too much, is pretty much the most successful open source game https://www.openttd.org/
10:27:17 
<cfbolz> Carl Friedrich Bolz-Tereick awesome!
10:27:37 
<andythenorth> Textual User the main mods are compiled to an archaic bytecode format, which we (not me) wrote an intermediate python compiler for 
10:27:47 https://github.com/openTTD/nml
10:28:02 it historically was dog slow, especially under python 2
10:28:27 it has got faster and faster under python 3, and has caching between runs, and a small amount of c module I believe
10:28:36 
<cfbolz> Carl Friedrich Bolz-Tereick right
10:28:58 
<andythenorth> Textual User but on intel mac at least, pypy3 was typically twice as fast in many cases
10:29:19 cutting cycle times from e.g. 40s to 20s, which is a big deal when drawing tiny pixel changes and testing them in game
10:29:33 examples of mods https://grf.farm/iron-horse/2.31.0/html/tech_tree_table_red.html
10:29:49 https://grf.farm/firs/4.4.0/html/economies.html
10:30:20 I also do a bunch of automated graphics processing using PIL / Pillow which is also typically faster under pypy3
10:30:39 
<cfbolz> Carl Friedrich Bolz-Tereick oh nice! I had no clue that Pillow benefits from pypy
10:30:42 
<andythenorth> Textual User although parallelising that via multiprocessing pool made the biggest difference
10:30:58 
<cfbolz> Carl Friedrich Bolz-Tereick makes sense
10:31:10 
<andythenorth> Textual User I think the pillow improvement is subjective to workload, I am not good at profiling though :)
10:31:15 I just run 'time make'
10:31:21 and try different pythons
10:31:44 
<cfbolz> Carl Friedrich Bolz-Tereick that's a good approach ;-)
10:32:37 
<andythenorth> Textual User I actually code generate the mod language from pure python and abuse of Chameleon (zope/pyramid) templates
10:32:52 Chameleon is not intended for that, but I know how to use it and it works
10:33:06 interestingly, last time I tested, Chameleon was notably slower under pypy3
10:33:38 it pre-compiles templates to pyc, not sure of the details, but maybe that approach is in conflict with JIT (I am out of my depth)
10:34:12 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: ah, interesting! did you try with the recent pypy 3.8 beta release?
10:34:18 
— andythenorth looks
10:34:23 
<andythenorth> Textual User meanwhile repos are https://github.com/andythenorth/iron-horse/ and https://github.com/andythenorth/firs if anybody ever wanted to test
10:34:36 there's no build tool, deps are listed in the docs somewhere though
10:34:46 https://grf.farm/firs/4.4.0/html/code_reference.html
10:34:58 
<cfbolz> Carl Friedrich Bolz-Tereick we made a change in the recent 3.8 there that has a pretty decent chance to improve chameleon for complicated templates
10:35:13 
<andythenorth> Textual User oh that's interesting
10:35:18 is it a known case then?
10:35:53 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: not chameleon specifically
10:36:02 but templating engines that generate code in general
10:36:07 not really known, we found out this year
10:36:57 
<andythenorth> Textual User looks like I have `[PyPy 7.3.7 with GCC Apple LLVM 13.0.0 (clang-1300.0.29.3)] on darwin`
10:37:13 can't remember if I compiled it or installed the binary
10:38:25 oh you have nightlies ok
10:38:38 
<cfbolz> Carl Friedrich Bolz-Tereick yeah, you could try a 3.8 nightly
10:40:30 andythenorth: anyway, this is all quite fascinating :-)
10:43:07 
— andythenorth just trying to install the beta safely without trashing my env and paths :D
10:43:11 
<andythenorth> Textual User I will compare times
10:54:10 hmm something is broken with Pillow when I pip install to the 3.8 beta :)
10:54:35 I'm not great at resolving that kind of issue, but it's not urgent 
10:57:42 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: something deep in your setup, I assume?
10:57:52 
<andythenorth> Textual User probably :)
10:58:07 
<cfbolz> Carl Friedrich Bolz-Tereick :-)
10:58:07 
<andythenorth> Textual User I seem to have broken my previous pypy3 venv, but I'll figure it out somehow
10:58:53 
<cfbolz> Carl Friedrich Bolz-Tereick anyway, if you want to, this is clearly very cool, we should just dump it into a post. The numbers don't even matter too much
11:02:19 
<andythenorth> Textual User yup I will hang out in this channel for a bit and do a post at some point :)
11:03:30 
<cfbolz> Carl Friedrich Bolz-Tereick cool
11:18:20 
<andythenorth> Textual User timings for 3.10 official binary with arm, vs pypy3 x86 running in rosetta2
11:18:23 ../../pypy3/bin/nmlc -l generated/lang --verbosity=4  generated/iron-horse.nm  11.01s user 1.02s system 98% cpu 12.212 total
11:18:30 nmlc -l generated/lang --verbosity=4 --nfo=generated/iron-horse.nfo    23.92s user 0.83s system 99% cpu 24.889 total
11:18:50 even on transpiled x86, that's twice as fast
11:19:12 
<LarstiQ> Wouter van Heyst cool
11:19:13 
<andythenorth> Textual User this is super helpful when just tweaking a few pixels etc
11:19:33 this is the m1 pro, 10 core thing
11:19:56 obvs only loads one core
11:21:26 
<cfbolz> Carl Friedrich Bolz-Tereick right
11:39:41 
<andythenorth> Textual User same python 310 / pypy3, but for the chameleon part of the pipeline
11:39:45 python src/render_nml.py  1.93s user 0.12s system 94% cpu 2.162 total
11:40:05 python src/render_nml.py  12.12s user 0.50s system 98% cpu 12.839 total
11:40:18 this is a case where pypy3 is unusually slower
11:40:42 I did also try the latest nightly, about the same
11:41:17 I don't trust the results though, because chameleon builds these bytecode pre-compiled templates
11:42:23 nah same result after I clear out those
11:42:53 job is here if anybody likes investigating weird cases :D https://github.com/andythenorth/iron-horse/blob/master/src/render_nml.py
11:43:05 deps are chameleon and markdown, both installed fine from pip for me
11:43:32 
<cfbolz> Carl Friedrich Bolz-Tereick :-(
11:43:34 pity
11:43:49 
<andythenorth> Textual User well I tend to look at the wins :)
11:44:02 I just call different pythons from different parts of the makefile
11:44:08 whichever is fastest for the job
11:46:35 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: made an issue: https://foss.heptapod.net/pypy/pypy/-/issues/3597
11:46:54 
<andythenorth> Textual User thanks :)
11:47:24 I'm doing something chameleon isn't supposed to do :)
11:57:30 
<cfbolz> Carl Friedrich Bolz-Tereick andythenorth: hah, "supposed"
11:58:43 
<andythenorth> Textual User I haven't asked chameleon devs, but I think generating 600 files from templates in 3s is probably beyond the intended use :)
11:59:27 in website use, the requests don't usually come that fast, and would have varnish or something in front of them I guess

/cc @andythenorth