Stdlib or Third-Party? Empirical Performance and Correctness of LLM-Assisted Zero-Dependency Python Libraries
This paper presents "zerodep," an open-source collection of LLM-assisted, single-file Python standard library re-implementations of popular third-party modules, demonstrating that while C-extension-heavy tasks remain a performance bottleneck, stdlib-only alternatives often achieve comparable speed or even significant speedups by eliminating architectural overhead, thereby validating the feasibility of dependency-free software engineering with high correctness.
Original paper licensed under CC BY 4.0 (http://creativecommons.org/licenses/by/4.0/). This is an AI-generated explanation of the paper below. It is not written or endorsed by the authors. For technical accuracy, refer to the original paper. Read full disclaimer
Imagine you are building a house. In the world of Python programming, the "Standard Library" (stdlib) is like a high-quality, pre-packed toolbox that comes free with every Python installation. It has hammers, screwdrivers, and saws. However, for specific, fancy jobs, programmers often buy "Third-Party Libraries." These are like specialized, branded toolkits you download from the internet. They are powerful, but they come with a catch: they often require you to buy other tools just to use them (dependencies), they might break if the brand changes its rules, and they can introduce security risks if the brand is compromised.
This paper, titled "Stdlib or Third-Party?", asks a simple but profound question: How much of that fancy, specialized toolkit can we actually rebuild using just the free, basic tools we already have?
To answer this, the authors created a project called zerodep. Think of zerodep as a "DIY Workshop" where they took 44 popular, complex Python tools and tried to rebuild them from scratch using only the standard toolbox. They didn't do this alone; they used an AI assistant (an LLM) to help write the code, but they put the AI on a very strict leash:
- No new tools allowed: You can't import anything that isn't already in the standard Python box.
- One file only: The whole tool must fit in a single sheet of paper (a single
.pyfile). - Drop-in replacement: It must work exactly like the original tool so you can swap them without breaking your house.
- Proof of work: The AI's creation must pass a rigorous test against the original to prove it works correctly.
The Three Main Findings
The researchers tested these 44 rebuilt tools against the originals and found three distinct "zones" of performance:
1. The "Lightweight Win" Zone (The AI did great here)
For many common tasks, the original third-party tools were actually over-engineered. They were like a Swiss Army knife with 50 gadgets when you only needed a screwdriver. The AI, forced to use only the basic tools, built a simple, streamlined screwdriver that was actually faster.
- The Analogy: Imagine a restaurant that serves a complex, multi-course meal just to get you a glass of water. The zerodep version is just a glass of water. It's much faster to get.
- The Result: In categories like reading configuration files, handling retries (trying again if something fails), and parsing text, the AI-built tools were often 5 to 115 times faster than the originals because they cut out all the unnecessary "bloat."
2. The "Parity" Zone (Good enough)
For about two-thirds of the tools, the AI-built versions were just as good as the originals. They might be slightly slower or slightly faster, but they were within a "safe margin" (less than 2x difference).
- The Analogy: It's like driving a reliable sedan versus a luxury sports car. The sports car (third-party) might be slightly faster, but the sedan (stdlib) gets you to the same destination in almost the same time, without needing a special mechanic to fix it.
- The Result: For tasks like basic networking or data validation, the standard library is perfectly capable of doing the job without needing extra downloads.
3. The "Hard Wall" Zone (The C-Extension Cliff)
There was one place where the AI and the standard library hit a brick wall: heavy math and low-level processing.
- The Analogy: Imagine trying to paint a massive mural. The third-party tools use a team of professional painters with industrial spray guns (compiled C or Rust code). The AI, restricted to the standard library, is forced to use a tiny paintbrush and a bucket of paint. No matter how hard the AI tries, it cannot compete with the speed of the industrial spray gun.
- The Result: For things like processing images (pixels), heavy cryptography (encryption), or complex binary data, the standard library was significantly slower (sometimes 300x slower).
- The Workaround: The authors found a clever trick: instead of painting the mural themselves, they built a small door in the wall and asked the professional painters (the system's built-in C libraries) to come in and do the heavy lifting. This "subprocess" trick allowed them to get the speed of the pros without needing to download new tools.
The Role of the AI (LLM)
The paper also looked at how well the AI did the work.
- Simple Tasks: For small, simple tools, the AI was a wizard. It could write a working version in one or two tries.
- Complex Tasks: For huge, complicated systems (like a full web server), the AI got confused. It needed a human architect to draw the blueprints first. Once the human set the structure, the AI could fill in the details.
- The Safety Net: The most important part of the process was the "Correctness Test." The AI would guess, the test would say "Wrong," and the AI would try again. This loop ensured that the final product actually worked, preventing the AI from "hallucinating" (making up) fake tools that don't exist.
The Bottom Line
The paper concludes that for most everyday programming tasks, you don't need the fancy third-party tools. You can often build a faster, safer, and lighter version using just the standard library, especially with the help of an AI.
However, if you are doing heavy-duty work like image processing or high-speed encryption, the standard library hits a speed limit that only specialized, compiled code can break. In those cases, you either need the third-party tools or a clever workaround to borrow power from the system's native code.
In short: For 2/3 of your programming needs, the "free toolbox" is all you need, and it might even be faster. For the other 1/3, you still need the specialized gear, but you now know exactly where the line is drawn.
Drowning in papers in your field?
Get daily digests of the most novel papers matching your research keywords — with technical summaries, in your language.