Measured benchmark · Workflow performance
How I reduced memory pressure in my AI agent workflows
What I changed when AI agents kept filling my Mac’s memory, plus the source and results from a million-row CSV test in Rust and Python.
I have a 36 GB MacBook Pro, and I kept running out of memory while working in Codex and Antigravity. The agents were starting multiple copies of Chrome to browse websites and generate documents. At the same time, Python jobs were processing large county property-assessment CSVs.
I started changing the tools they ran. PDF generation moved to Typst, and large-data jobs moved toward Rust. We also changed the skills and commands so the agents would use those tools the next time.
The work felt faster and used less memory. To put numbers on the CSV part, we later built a separate test with synthetic data. The results are below, along with the source if you want to run it yourself.
Move document generation out of the browser
Generating a PDF was an easy place to stop launching Chrome. Typst has a local compiler that takes a document template and produces a PDF. Its documentation shows the command:
typst compile report.typ report.pdf
The agents still use a browser for websites. Documents now have a separate path through the compiler. The JSON-to-PDF tutorial includes a template, fictional work items, and the PDF they produce.
Move large CSV processing from Python to Rust
I had been using Python for county assessment CSVs. Moving that processing to Rust helped with both speed and memory in my workflow. I didn’t measure those earlier jobs closely enough to report a reliable before-and-after figure, so the published benchmark uses a separate, repeatable workload.
Python CSV reader memory usage
Python’s csv.reader can process a file one row at a time. Memory grows when the program keeps the decoded rows. Calling list(reader) retains them all, including their lists and strings, before the next processing step.
On our million-row synthetic file, Python’s median peak process memory fell from about 846 MiB to 19 MiB when we switched to streaming, a reduction of roughly 98%. Both versions validated the same fields, calculated the same totals, and produced the same hash. The streaming version kept running results without retaining every row.
If your job only needs totals and validation, check whether it is holding onto rows it has already processed. Streaming can reduce memory use in either language. A job that needs every row available at once needs a different approach or more memory.
This comparison uses Python’s standard-library CSV reader and Rust’s csv crate. Python libraries backed by other native engines need their own measurements. The results below apply to these implementations and this workload.
The benchmark source package includes both approaches and reproduction instructions. The October 10 raw results retain the timings, peak memory, input hashes, and environment used for the published numbers.
Put numbers behind the CSV workflow
The test data has the shape of an assessment CSV, but all its records are synthetic. It doesn’t contain actual property records or replay the earlier migration.
The larger file had 1,000,000 rows and was 159.46 MB. Python and Rust both read and parsed it, validated the numeric fields and totals, calculated aggregates, and hashed the parsed content with SHA-256. Every measured run produced matching results.
We tested two ways of processing the file in each language: streaming one row at a time, and loading all the decoded rows into memory before processing them.
These are the rounded medians of five fresh-process runs on the million-row file:
| Implementation | Time | Peak process memory |
|---|---|---|
| Python, streaming | 3.3 s | 19 MiB |
| Rust, streaming | 1.0 s | 6.2 MiB |
| Python, all rows buffered | 4.8 s | 846 MiB |
| Rust, all rows buffered | 1.1 s | 385 MiB |
Rust was 3.3× faster and used 68% less peak process memory when both implementations streamed the rows. With both implementations buffering every row, it was 4.6× faster and used 55% less peak process memory. Comparing the same processing approach in each language keeps those figures meaningful.
The graphs show the same rounded medians. Comparisons use the unrounded measurements.
The smaller, 169,727-row file was 26.97 MB. Streaming Python took 0.543 s versus Rust’s 0.160 s, with peak memory of 19.48 MiB versus 6.20 MiB. Buffered Python took 0.655 s versus Rust’s 0.175 s, with peak memory of 159.89 MiB versus 70.16 MiB.
What these numbers measure
We ran this on an Apple M3 Pro MacBook Pro with 36 GB of memory, macOS 26.6.1, Python 3.12.14, and Rust 1.98.1. Rust used an optimized release build and the csv crate, version 1.4.0. Python used its C-backed standard-library CSV parser.
There was one excluded warmup for each implementation and file size, followed by five measurements. The file cache was warm, and normal applications stayed running. Times include process startup, file reading, parsing, validation, aggregation, and hashing. They exclude compilation and fixture generation.
Times varied between runs. On the million-row file, streaming Python ranged from about 3.2–5.0 s, versus 0.9–1.6 s for Rust. Buffered runs ranged from about 4.7–8.7 s for Python and 1.0–1.2 s for Rust. These are observed ranges, not confidence intervals.
Peak process memory is the maximum resident set size reported by macOS for each child process, converted to MiB. It measures the process’s memory rather than estimating it from object sizes. It doesn’t include the rest of the Mac’s memory use.
The timings exclude database imports, Chrome, Typst, document generation, and model calls. My earlier impression of a roughly 10× improvement remains an observation about that work; this test measures only these CSV implementations on this machine.
Download all raw benchmark measurements, including the excluded warmups, fixture hashes, and environment details. Only synthetic data was used; local file paths have been removed from the download.
Download the benchmark source, including the synthetic data generator, Rust runner, unchanged Python baseline, tests, and reproduction instructions. The portable runner replaces the original machine-specific interpreter path and omits chart rendering. Its source hashes are separate from the measured originals. New runs record their own timings; they do not replace the October 10 measurements.
Change the skills and commands the agents use
After replacing a tool, I wanted the agents to keep using the replacement. We updated their skills, shell commands, and aliases to prefer the Rust tools we’d selected.
I also asked them to search GitHub and Homebrew for existing tools before writing a replacement. A maintained command that already handles the job can save us from having to build and maintain our own.
Add an automatic daily review
We added a daily job to review agent sessions, tool calls, and errors. It was configured to apply fixes and suggest or use Rust alternatives. That job is part of how we maintained the setup; its effect isn’t measured in the CSV results.
Rust helped. Streaming mattered too.
Switching from buffering to streaming reduced peak memory by about 98% in both languages: from 846 MiB to 19 MiB in Python, and from 385 MiB to 6.2 MiB in Rust. That was the largest memory difference in this test.
I’d check how much data a job keeps in memory before choosing a replacement language. For this CSV job, Rust’s streaming implementation then gave us another reduction in memory and a shorter runtime. The downloadable source lets you try the same comparison on your machine.