Prospero challenge, now with more garbage collection
Published on: 2025-05-31 09:56:29
Matt Keeter put up The Prospero Challenge, which is like catnip for me. It’s a well-scoped project: we have a slow program. Make it faster within these constraints. In this post, I will describe two very small changes that can speed up his sample program with minimal effort.
His sample tiny implementation, which I will reproduce here, uses Python and NumPy to compute pixels in parallel while parsing the input:
import numpy as np with open ( 'prospero.vm' ) as f : text = f . read (). strip () image_size = 1024 space = np . linspace ( - 1 , 1 , image_size ) ( x , y ) = np . meshgrid ( space , - space ) v = {} for line in text . split ( '
' ): if line . startswith ( '#' ): continue [ out , op , * args ] = line . split () match op : case "var-x" : v [ out ] = x case "var-y" : v [ out ] = y case "const" : v [ out ] = float ( args [ 0 ]) case "add" : v [ out ] = v [ args [ 0 ]] + v [ args [ 1 ]] case "sub" : v [ out ] = v [ args [ 0 ]] - v [ args [ 1 ]] case "mul" : v [ out ] = v [ args [
... Read full article.