A Developer Used Codex to Write LastPNG, a PNG Compressor 12 Times Faster Than Standard libpng
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.
AI-processed from Habr AI; edited by Hamidun News
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.
- Nov 29, 2026Five Malicious GGUF Repositories Found Among 3.27 Million on Hugging Face, Downloaded 2,428 Times
- Nov 29, 202615 Open-Source Repositories Build a 3D Animated Film: From Sketch to Render
- Nov 29, 2026Load Test Finds Radio Sending More Control Traffic Than Audio in AI-Written Code: 23 Mbit/s Drops to 0.12 Mbit/s
- Nov 29, 2026Windows Trojan Found in Two GGUF Models on Hugging Face: 3.27 Million Repositories Checked
Key Questions Answered
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.
What are the key details on 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.
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.
Free 2-Day Vibecoding & AI Agents Intensive
Day 1: the autonomous Hermes + DeepSeek AI agent — vibecoding and development on par with Claude Code / Codex / Gemini. Led by Jemal Hamidun, Head of AI at Alpina Digital and academic supervisor at MIPT. Right after you register with our bot Nika: the recording + 11 materials from the previous intensive.
Daily 60-sec AI Voice Brief + Weekly Production AI Agent Playbook
Listen to a 60-second AI news brief every morning and get a weekly hands-on playbook for shipping AI agents to production — tools, MCP servers and patterns that work. Curated by Jemal Hamidun, Head of AI at Alpina Digital.
