Skip to content

Instantly share code, notes, and snippets.

View mattip's full-sized avatar

Matti Picus mattip

  • Quansight Labs
View GitHub Profile
@mattip
mattip / exceptiontable.md
Last active April 13, 2026 10:14
Exception table plan II

Exception Table Migration Plan (April 13 commit b350a6b)

Architecture

Current PyPy: runtime linked list of FrameBlock objects (ExceptBlock, FinallyBlock, SysExcInfoRestorer) anchored at frame.lastblock. The compiler emits SETUP_FINALLY/SETUP_EXCEPT/POP_BLOCK to manage this list. On exception, unrollstack() walks the list to find the handler.

CPython 3.11: no block stack at all. The exception table co_exceptiontable maps bytecode offset ranges to (handler_offset, stack_depth, lasti_flag). Only consulted when an exception actually fires — zero overhead on the happy path.


@mattip
mattip / migration.md
Created April 11, 2026 19:50
Plan a move from buildbot to github actions

Migration Plan: Buildbot → GitHub Actions for PyPy

Platform matrix

Platform GitHub runner Container image (source)
linux-x86-64 ubuntu-latest (hosted) ghcr.io/pypy/pypy/buildslave_x86_64 (docker/Dockerfile)
linux-x86-32 ubuntu-latest (hosted) ghcr.io/pypy/pypy/buildslave_i686 (docker/Dockerfile32)
linux-aarch64 ubuntu-24.04-arm (hosted) ghcr.io/pypy/pypy/buildslave_aarch64 (docker/DockerfileArm64)
macOS x86-64 macos-13 (hosted, Intel) none
@mattip
mattip / exceptiontable.md
Last active April 12, 2026 10:01
Plan porting CPython exception table to PyPy

Exception Table Migration Plan

Architecture

Current PyPy: runtime linked list of FrameBlock objects (ExceptBlock, FinallyBlock, SysExcInfoRestorer) anchored at frame.lastblock. The compiler emits SETUP_FINALLY/SETUP_EXCEPT/POP_BLOCK to manage this list. On exception, unrollstack() walks the list to find the handler.

CPython 3.11: no block stack at all. The exception table co_exceptiontable maps bytecode offset ranges to (handler_offset, stack_depth, lasti_flag). Only consulted when an exception actually fires — zero overhead on the happy path.


@mattip
mattip / gist:c91cc9a1ea0d01b5704dc026d6e61b05
Created April 5, 2026 20:08
Compare pypy benchmarks with pyperformance benchmarks
Summarize the differences between pypy's benchmarks and CPython's:
PyPy benchmark suite vs pyperformance
Framework
All pyperformance benchmarks use pyperf.Runner which handles warmup automatically (discards early iterations) and runs multiple processes. The PyPy suite uses the old unladen_swallow util.run_benchmark
with no warmup support.
Methodology fixes in pyperformance
@mattip
mattip / analyze_failures.py
Created April 1, 2026 07:52
Analyze lib-python failures
#!/usr/bin/env python3
import re
import sys
import urllib.request
BUILD_NUMBER = 11645
BASE_URL = (
"https://buildbot.pypy.org/builders/pypy-c-jit-linux-x86-64"
"/builds/{build}/steps/shell_6/logs/stdio/text"
@mattip
mattip / gist:ddea7bcc455218a7487e8767675fc289
Last active April 30, 2025 06:36
commit 6ccbd45e79cb pickle benchmarks
# commit 6ccbd45e79cb
# running runner.py --baseline ../pypy3.11-v7.3.19-linux64/bin/pypy --changed /tmp/venv311pypy/bin/pypy -b \
# pickle,pickle_dict,pickle_list,cpython_doc,unpickle,unpickle_list
{
"revision": null,
"results": [
[
"sphinx",
"RawResult",
{
@mattip
mattip / float_summation.md
Last active November 20, 2024 06:10
Exploring fast and accurate floating point summation

From numpy/numpy#22956

Here is some code implementing a kahan summation. It is not fast

import cffi
import numpy as np
import time

ffi = cffi.FFI()
ffi.cdef("""
@mattip
mattip / gist:7eb1c97169b00d844dff5a2f30a27d0a
Created November 1, 2024 08:36
Explore 3.11 bzip test hang in multiple threads
The problematic place in the code is in the compression, when the test does compression in many threads:
```
def testThreading(self):
# Issue #7205: Using a BZ2File from several threads shouldn't deadlock.
data = b"1" * 2**20
nthreads = 2
with BZ2File(self.filename, 'wb') as f:
def comp():
for i in range(5):
# f.write(data) # original test does this, change for debugging
@mattip
mattip / gist:71e0d0f0c212a04afd955d470f63dbc2
Last active December 3, 2023 18:35
stack just before recursion error
Running `python -c "import numpy", I get a recursion error. Running a lldebug0 build under gdb, here is the backtrace.
Searching for cpyext, I see there is a chain starting around frame 75 that maybe I can do something about.
But why are there 40 recursive calls to `pypy_g_dispatch_bytecode__AccessDirect_None` ?
#0 __pyx_pf_5numpy_6random_13bit_generator_12SeedSequence_4generate_state (__pyx_v_self=0xcfb1c0, __pyx_v_n_words=0xcfd7b0, __pyx_v_dtype=0x95de18)
at numpy/random/bit_generator.c:6289
#1 0x00007fffec5c0cc5 in __pyx_pw_5numpy_6random_13bit_generator_12SeedSequence_5generate_state (__pyx_v_self=0xcfb1c0, __pyx_args=0xcfd960,
__pyx_kwds=0xcfd9b0) at numpy/random/bit_generator.c:6114
#2 0x00007ffff2b4446f in pypy_g_cpy_call_external__funcPtr__objectPtr__objectPtr_1 (
@mattip
mattip / gist:7df3e9f37b8b3bdc6faab0b44594ac4e
Created January 16, 2023 08:19
lib-python failures py3.10 Jan 16
$ grep '^[A-Za-z]*Error' /tmp/stdout.txt |sort |uniq -c |sort -n -r
65 AssertionError: DeprecationWarning not triggered
48 AssertionError: TypeError not raised by dumps
42 AssertionError: events did not match expectation:
16 AssertionError: Lists differ: [1, 1] != [2, 2]
13 ValueError: array.index(x): x not in list
13 AssertionError: UnicodeEncodeError not raised
8 AssertionError: TypeError not raised
7 SyntaxError: invalid syntax
6 AssertionError: 4294967298 != 0