---
id: 18659
lang: en
title: "A Developer Used Codex to Write LastPNG, a PNG Compressor 12 Times Faster Than Standard libpng"
published_at: "2026-11-29 22:25:29"
source_name: "Habr AI"
source_url: "https://habr.com/ru/articles/1113796/?utm_campaign=1113796&utm_source=habrahabr&utm_medium=rss"
canonical_url: "https://news.hamidun.com/en/news/18659"
categories: ["llm", "autonomous"]
publisher: "AI News by Jemal Hamidun (news.hamidun.com)"
---

# A Developer Used Codex to Write LastPNG, a PNG Compressor 12 Times Faster Than Standard libpng

> **Краткая суть (BLUF):** A developer used the Codex agent to write LastPNG, a PNG compressor that runs 12 times faster than the standard libpng-plus-zlib pairing (level 6) at the same file size. On a test set of 4,079 images (1 GB), level 2 finished in 11.47 s compared with 146.11 s, and the output came to 914 MB versus 916 MB. Ideas for speeding things up came from a second "colleague" agent, not from subordinate subagents. The takeaway: ask agents directly to propose hypotheses.  - Level 3 is 10 times faster than libpng+zlib-ng level 9, with files about 6% smaller. - Fastest mode: 2.94 s versus 3.99 s for rust-png fastest. - The author considers the level 6 neural network with 1,584 parameters experimental.

Anyone who stores or ships large numbers of images faces the same choice: a PNG can be compressed fast or compressed small, and there is almost no middle ground. The standard is the libpng library, which compresses data through zlib at level 6. The author of this Habr experiment used the Codex AI agent to write LastPNG, a compressor that runs 12 times faster at the same file size. Along the way, he tested a hypothesis about how to organize work among several agents. The impetus was unused capacity: at the end of the week, more than half of the 7-day Codex limit remained.

## How the Test Bench Was Built

The original idea was simple. Conventional compressors rely on zlib, and zlib knows nothing about the fact that pixels are inside the data. Filtering and compression run as separate stages in them. There are almost no settings between the "as fast as possible" and "as small as possible" modes.

First, the agent assembled a test corpus: in 25 minutes, 4,079 static PNG files totaling exactly 1,000,000,000 bytes appeared on disk. Then the benchmark bench took about two hours to set up. The competitors were libpng with zlib and with zlib-ng, the Rust png library, OxiPNG, ZopfliPNG, and OptiPNG. The heavy contenders take a long time: OxiPNG at levels 0–6 takes about 3 hours 58 minutes, ZopfliPNG 5 hours 32 minutes, and OptiPNG 5 hours 36 minutes. The bench was needed to see, in a single run, which strategies the competitors choose and where they win.

## A Colleague Instead of Subordinates

The author started from an observation: agents are good at finding information, building connections, and analyzing. They also produce mid-quality ideas, but only if you explicitly ask, "how could this be done better?" They don't ask that question on their own. Subagents that are handed the full cycle of "find the problem and fix it" don't ask it either. An hour of work piles up with many small suboptimal decisions and throwaway code.

So the main agent set up not a subordinate but a colleague. It was asked in turn which hypotheses for speeding up and compressing should be tested. The colleague researched the topic and proposed an idea, and the main agent checked it against the corpus. An idea made it into the code only when file size improved. The code did not balloon, and with each iteration it ran faster.

## What Came Out

The library was named LastPNG, a name that sounds like both "fast" and "Rust." According to the author's table on the 1 GB corpus:

- Fastest mode (level 1): 2.94 s and 1,279.69 MB versus 3.99 s and 1,418.88 MB for rust-png fastest. It is both faster and more compact.
- Level 2: 11.47 s and 914.49 MB versus 146.11 s and 916.26 MB for libpng with zlib level 6. That is about 12 times faster at the same size.
- Level 3: 26.53 s and 837.14 MB versus 261.66 s and 886.67 MB for libpng with zlib-ng level 9 (the maximum that can be squeezed out of libpng). That is 10 times faster, and the output is about 6% smaller.
- Level 4: 66.77 s and 816.88 MB. It beats OxiPNG level 0 (94.26 s and 824.74 MB) on both speed and size.

Beyond that, the heavy algorithms still win. ZopfliPNG gets 756.95 MB in 14,244 seconds, while LastPNG level 6 gets 768.54 MB in 638.87 seconds. The author was unable to speed those algorithms up.

## Trade-offs

The hypothesis that libdeflate would compress better if it were given hints about pixel structure paid off. To do this, the library had to be placed in /vendor and patched many times for special cases. The author also had to work out what competitors do where they win. He broke their advantage down into components and looked for ways to reproduce it faster or better.

At level 6, a neural network with 1,584 parameters was built into the encoder. Based on image characteristics and the encoder's internal state, it predicts which PNG filter to apply to a row. It takes match hints from the same libdeflate copy. The author is not happy with the result, so he considers level 6 experimental.

There are limitations as well. All figures come from a corpus the agent assembled itself, and no one has verified them independently. The author promises no project support. The library is available for Rust and as a Pillow plugin for Python.

The practical takeaway for anyone working with agents: let one agent periodically propose improvements and have a second agent verify each hypothesis with measurements. That keeps the code compact. It only works with an honest benchmark that quickly filters out weak ideas.

---
- **Первоисточник:** [Habr AI](https://habr.com/ru/articles/1113796/?utm_campaign=1113796&utm_source=habrahabr&utm_medium=rss)
- **Каноническая ссылка:** https://news.hamidun.com/en/news/18659
- **Экосистема автора:** [Бесплатный интенсив по вайбкодингу — предзапись в Нике](https://t.me/vibecodeguidebot?start=agent_intensive_news_md) · [Nomad AI](https://nomadnet.ai) · [Telegram @jemal_hamidun](https://t.me/jemal_hamidun)
