I've noticed that the OctoPrint instance on my Hypercube 300 (which was running on CPython 3.7) was a bit more responsive than the OctoPrint instance on my AM8 (which was running on CPython 2.7). I've since upgraded the AM8's OctoPrint so that it's on CPython 3.7 as well, but then I decided to try for a bit more speed and switch from CPython to PyPy.
There's just one snag: PyPy3 that's available in Raspbian is v7.0, which is compatible with CPython 3.5. OctoPrint wants 3.6 as a minimum. This is supported in newer versions of PyPy (7.3.1 is current), but building PyPy3 on a Raspberry Pi is an exercise in frustration. It won't build on my RPi 3s at all because they don't have enough RAM.
Solution: build PyPy3 for Raspbian on another host.
I installed qemu on my home workstation: a Ryzen 7 3800X with 32 GB RAM and a 512 GB NVMe SSD, running Gentoo. Pretty decent instructions for what follows are available at https://wiki.gentoo.org/wiki/Raspberry_Pi#Compiling_using_chroot; this is a summary.
Emerge qemu with at least these USE flags:
- static-user
- qemu_user_targets_arm
- qemu_user_targets_aarch64
Also, include --buildpkg among the options to emerge. We'll need a binary package to install into the Raspbian image later.
Download the latest Raspbian Lite image. Extract the two partitions from the image, and resize the root filesystem to at least 16 GB so you'll have room to install tools and build PyPy3. Loopback-mount the root filesystem someplace convenient (we'll use /mnt/rpi as an example), and do the same with the boot filesystem within it. Bind-mount /proc, /sys, and /dev at the appropriate points, and copy /etc/resolv.conf into the root filesystem.
Now, install the qemu binary package into Raspbian:
ROOT=/mnt/rpi sudo emerge --usepkgonly --oneshot --nodeps qemu
Make sure qemu binfmts are loaded:
sudo /etc/init.d/qemu-binfmt start
and chroot into Raspbian:
sudo chroot /mnt/rpi /bin/bash -l
At this point, you're running Raspbian on your desktop in emulation. Download the latest PyPy3, unpack it, and compile it according to the instructions at https://doc.pypy.org/en/latest/build.html. I don't know how to package software to integrate with apt-get, but the build process can produce a tarball that can be unpacked into /opt, and that works well enough for me. Building PyPy3 7.3.1 took somewhere around three hours, and I noticed that it never used more than 4 cores (of the 8 I have available).
Speaking of tarballs, this is the one I produced if you don't want to go to the trouble of making one yourself:
However you come by it, unpack it into /opt. You can then follow the OctoPrint installation instructions, summarized as follows:
cd ~
export PATH=$PATH:/opt/pypy3-7.3.1-raspbian/bin
virtualenv -p pypy3 octoprint-pypy3
octoprint-pypy3/bin/pip install OctoPrint
and then edit /etc/systemd/system/octoprint.service to point to ~/octoprint-pypy3 instead of wherever it's currently set to go. (Before doing that, you may want to back up and download your OctoPrint config so you can restore it in the new PyPy3-based instance.)