Repository navigation
Brevi v0.24.0
Agents now pay less with Brevi than with Python on heavy work. Told that their Python is compiled to native code, models write the plain solution instead of hand-optimising it; on four tasks with a 10 s limit the whole job cost 0.58x Python's with Sonnet and 0.53x with Haiku, every program built natively and no check failed because of Brevi. On the 24-task release suite, ordinary work, the bar is still met (1.07x Sonnet, 1.00x Haiku). Plain generators and string indexing now build typed and fast, first builds take about 35% less time, and seven bugs found by the new shadow check (each pyb check also runs CPython) are fixed.
- Write the plain version. The skill, the editor rules, the MCP server's text and llms.txt now tell agents that their Python is compiled to native code, which runs plain loops 10 to 50 times faster than CPython, so they should write the plain, direct solution and not hand-optimise it. In a test on the four
speedtasks, this one line cut output tokens by 50% for Sonnet and 28% for Haiku, and cost by 44% and 25%. Every plain program then ran natively within the 10 s limit, where CPython needs 29 to 59 s. bench/e2e.py adds the line to the pyb prompt (--no-hintleaves it out). - Plain idioms build typed and fast. An endless generator read only with
next()(a seeded random number source:def rng(seed): x = seed; while True: ...; yield x) used to send the whole program to the dynamic build. It is now rewritten into a small class, so the program builds typed. The speed set's plain reference programs go from 24 to 29 s to 1.8 to 2.5 s for knapsack, and from over 60 s to 2.3 s for Game of Life (CPython: 25 s and 30 s). Indexing a long text (a[i],b[j - 1]) scanned the whole text each time to check for ASCII; the answer is now kept until the text is freed, so a 10,000-letter edit distance takes 1.8 s instead of 15 s. - Faster cold builds. A build without
--release(whatbrevi runuses) of a program it has not seen takes about 35% less time: the 12 speed programs inbench/comparewent from 405 ms to 257 ms each on average on a 4-core machine (a hello world from 186 ms to 148 ms), and they run as fast as before (all 12 still beat CPython; all 591 saved solutions still match it). Brevi now calls rustc directly instead of through the rustup proxy (the proxy's choice of toolchain is remembered until PATH, rustup's settings or a rust-toolchain file change), uses one codegen unit per core (4 to 16) instead of rustc's 16, looks up rustc while the front end works, and no longer compiles a program twice when the build cache is off (BREVI_NO_CACHE=1, whichbench/compareuses, so its build times there were doubled). - Speed and correctness on fast-Python idioms (found by the new time-limited bench set, where models write optimised Python first). Typed builds: a row taken from a grid (
nrow = new[r]) and changed cell by cell was copied back into the grid after every cell, so a 600x600 Game of Life took 16 s; it is now written back once after the loop when nothing in the loop reads the grid (2.6 s; CPython 30 s). Small runtime helpers (indexing,%,//,+) are inlined into default builds.min(a, b, c)andmaxof three or more values, and built-ins passed tomap(map(sum, rows),map(abs, xs)), build typed instead of falling to the slower dynamic build. Programs that pack many fields into one int (2 ** (F * K),x << (F * w)) build over dynamic values instead of overflowing 64-bit ints. Dynamic builds:&,|and^on ints past 128 bits work (they raised NotImplementedError);bin,oct,hexandint(s, 2)/int(s, 16)on big ints are linear (a 360,000-bitbin()took 11 s);2 ** nis a shift (a bit-packed knapsack went from 20 s to 3 s). Big-int arithmetic borrows its operands instead of copying them (another bit-packed knapsack: 10.5 s to 7.1 s; CPython 6.2 s). - Silent wrong answers fixed.
out.extend(xs)orout += xson a list parameter did not change the caller's list (found by the e2e shadow check in a Haiku poker solution, where it cost 7 checks and the task). A list parameter changed and also returned (xs.append(x); return xs) was not changed for the caller. In dynamic builds,x >> nwith n over about a million bits shifted by a million instead. From the first release-suite runs with the shadow check (19 checks that failed only because of Brevi): a function givingNoneon one path and a list or dict on another (parse(tokens)returning None for bad input) read an empty list as None, so empty input was reported as invalid (such results are now dynamic values; the "may be None or empty" build error is gone).isinstance(r, tuple)was false for a tuple held as a dynamic value.all(c in digits for c in s)andany(...)over a text held as a dynamic value walked nothing, and[c for c in s]over a text gave the text instead of its characters. A list slot set by a nested function, in a list that held an int and None (found = [0, None]), was set on a copy (programs like this now build over dynamic values). Programs usingfractionsbuild over dynamic values, where a Fraction takes any denominator (unit tables stopped with "can't be held exactly"). Dynamic builds adddatetime.time(dt.time(),time(9, 30),datetime.combine(d, t)) andDecimal.scaleb. - Bench. e2e.py's
pybcheck also runs CPython on the same files and logs the pair per check (shadow); the summary'sbugcolumn counts checks that failed only because of Brevi. New setspeed(bench/ref/gen_speed.py): Game of Life, knapsack, edit distance and Collatz chains, small inputs and tens of millions of steps under the 10 s test limit. bench/replay.py replays saved conversations from their first failed check with different feedback (shorter diff feedback made retries 14% cheaper, about 2% of a whole run).
Prebuilt brevi compiler for Linux, macOS and Windows. brevi still needs rustc on the PATH to build programs; sh install.sh fetches it and picks the right download.