Posts

Showing posts from March, 2018

Investigating pypy frame drop

Image
pypy has spikes in time it takes occasionally when using cpyext, otherwise known as pauses. This is because it's deallocating lots of CPython objects all in one frame, rather than incrementally. This is likely to be addressed in a future release of pypy. Mainly it's a problem when creating and deleting lots of CPython objects (like pygame.Rect). Not pure python objects. To work around it for now, the src/rect.c has been changed to have a free list of python objects, so it doesn't alloc and dealloc them. Instead it maintains it's own list of rect PyObject pointers, and reuses them. This is done in PR #431 Use PYPY_GC_NURSERY=1m incminimark environment variables when running pypy. Below are timings of the default pygame, and default pypy (at time of writing). Then a benchmark showing the improvement with the rect freelist implemented in rect.c inside pygame. Then we also improve things by setting PYPY_GC_NURSERY=1m environment variable to change the ...

Windows pypy pygame build for testing.

Image
How to install pypy (fast python written in python) on windows and use the pygame dev build. pypy running pygame.examples.aliens on Windows 1) Get pypy. It's just a zip folder with all the stuff inside. https://bitbucket.org/pypy/pypy/downloads/pypy2-v5.10.0-win32.zip Unzip, and put into C:\pypy, so C:\pypy\pypy.exe exists. OR get the pypy3.exe from https://bitbucket.org/pypy/pypy/downloads/pypy3-v5.10.1-win32.zip Unzip, and put into C:\pypy3, so C:\pypy3\pypy3.exe exists. 2) Set the PATH environment variable, so that pypy.exe is found in your command prompt. https://www.opentechguides.com/how-to/article/windows-10/113/windows-10-set-path.html Or you can just do this each time you run a new cmd prompt. set PATH=%PATH%;C:\pypy\;C:\pypy3\ Or just cd C:\pypy to test it out. 3) Ensure pip is installed (pip is a weirdly named tool for installing things). pypy.exe -m ensurepip 4 ) Install a dev build of pygame. pypy.exe -m pip install pygame --pre 5...

pygame on pypy usable

Image
Hi, TLDR; I'm at the pypy sprint, and working through the remaining pygame-on-pypy-cpyext issues. https://youtu.be/WN1slc5O8os Surprisingly to me... it's already usable. That is pygame (same one that runs on cpython), works on pypy through its C extension API. pypy has good support for the CPython API (through a recompile) now. PyPy is the python language with a fast JIT, so your code can approach C speeds. And in some cases it can be faster than C. There was an issue with events stopping keyboard/mouse/etc from working. Lots of details in this issue describing the changes needed, so I hope other extensions encountering this will find it useful. https://github.com/pygame/ pygame/issues/419 But now that's fixed, every pygame app I tried on it has worked. Cat sitting in the fog and snow of Switzerland Why is this exciting? This is exciting to me because: pure python code being fast on pypy(after warmup), also mixed with the fast bit...

Drawing sound (as a waveform in pygame).

Image
I recently gave an example of pygame sound generation examples , and a few people asked for more. So... here we go! There's an infinite number of ways to visualize sound. A classic way is to draw it as a waveform . Sound samples drawn as a Waveform. Scaled into a 320x200 sized Surface. A sound could be made up of 44100 samples per second. Where each sample is often a 16 bit number (or 8bit or a 32bit floating point). Python comes with a built in array for efficiently storing numbers. We can store samples in there, with integers between -32768 and 32768. This is a signed 16bit(2 byte) number. Two to the power of 16 is 65536, and if we divide that by two we see the minimum and maximum value that can hold. pow(2, 16) / 2 == 32768. Below is the annotated code, also with an example of an array of samples representing a square wave. We loop over the samples and draw a line from the previous sample to the current one. 0 to 1, 1 to 2, 2 to 3, ... N-1 to N. You can also fin...

Sound generation pygame examples.

Here's a few sound generation examples with pygame (and no numpy/scipy). If there's interest I'll expand this into a bigger example? Let me know. All the basics for making a music program (sampler/synth). some sample rate conversion, bit rate conversion tone generation using generators (square wave) python arrays used as buffers for pygame.Sound (zero copy). """ Some examples for generating and converting sounds for pygame. Python 2.7, 3.6 Shows: - a simple 'square wave' generated - resampling sample rates (eg, 8363 to 44100) - using built in python array for making pygame.Sound samples. - samples at different bit sizes - converting from signed 8 to signed 16bit - how initializing the mixer changes what samples Sound needs. - Using the python stdlib audioop.ratecv for sample rate conversion. Square Wave https://en.wikipedia.org/wiki/Square_wave MOD (file format) https://en.wikipedia.or...

pypy sprint

Been doing a bit of reading this morning on pypy things. Trying to prepare myself a bit for the coming ' winter sprint '. One topic I'm interested in for the sprint is finishing off remaining issues for pygame running on pypy. Probably not the most common reason for people to go to the Swiss mountains I guess! So this means learning about the cpyext part of pypy... the one which allows it to use the python C API, and modules that use it. Open source sprints are great. A bunch of people get together trying to make things. A very rare time when people get to meet other people-from-the-internet. It's a great place to learn, and to see how projects you're interested in are made. I guess I'm a little bit too excited, and started playing with pypy early. Below are some notes from my investigations finding out how to do things. Getting started, finding docs. There's a getting started guide for pypy which has some basic notes on running tests, and compil...

pygameweb - 0.0.4 - Northern Rockhopper Penguin

Image
pygameweb is the source code for the pygame website at https://www.pygame.org/ Northern Rockhopper Penguin (photo by Brian Gratwicke) #52 Adding ability to deploy through travisci. And docs. #46 Wiki readability. Wiki tools on left out of reading line. Twitter card for releases. For nicer view when posting to twitter. Wiki table of contents improvements. builds docs for pygame, when something lands on pygame github master branch. project release feeds bugfix. Only show one recent release for each project. Some projects release a few times in a row. Wiki, nicer pre code handling. Wiki code uses inline colors, so copy/paste works with colors too. use https for login and register buttons, even when on http (see Why can't we turn off HTTPS? ). Ask more bad robot web crawlers not to be bad. See a full diff of changes since last release .

On the threshold of a journey with a Jedi, a Sphinx, and a Homebrew.

Feels like practice. It all started some days ago, late at night, with a comment made by someone on the internet... "Threshold does not take keyword arguments" As is often the case when you want to correct something on the internet, this comment lead me on a journey (not one where I sell numpy for 22 million monies, a different type of journey involving text editors and compilers, and lots of failing tests). Software archeology -- not with Indiana, but at least there was a Jedi and a Sphinx. "Relax. Don't worry. And have a homebrew." -- Charlie Papazian And with a warm brew in hand, herein begins my tale... Starting at the end, where all poor stories start, with the comment I will send "TheBob427" (actual real nick), right after I publish this blog post... [ -1 ] Dear TheBob427, yes, this function doesn't take keyword arguments and you are right that it's super buggy. However, now after some da...

Pre release pygame builds through pypi and pip.

(If there's any python packaging experts reading this, please comment if this doesn't seem reasonable. https://github.com/pygame/pygame/issues/409 You will get 42 internet points, and a cookie if you ever visit Berlin). We want to be able to more widely test pre release builds, to avoid bugs and try things out on different OS/hardware combinations. This is the plan on how it will be done for pygame . --- Pre release 'dev' and release candidate('rc') builds of pygame through pip and pypi. every merge into master releases a dev build. 1.9.4.dev1+git.77.facebeef123 every release candidate tagged releases an rc build. 1.9.4.rc1 How to install pre release builds. Pip pre-release documentation `pip install pygame --pre` Requiring a specific development build is possible according to the documentation. `pip install pygame==1.9.4.dev1` Version naming. From packaging guide pre release versioning : zero or more dev releases (denoted with a “....