AI Rewrites Python Code to Rust in One Shot? The Amazing Transformation of Terminal Customization

An image of a code terminal on a black screen with colorful terminal effects applied
AI Summary

We examine a case where AI successfully converted a Python-based terminal effect library into Rust in a single shot, boosting performance by over 9 times.

Imagine this: a rigid terminal screen filled only with white text on a black background suddenly displays green code cascading like rain, or fiery flame effects, just like the movie The Matrix. There is a tool called ‘TerminalTextEffects (TTE)’ that allows developers to make their terminals—often seen as exclusive domains for serious work—a bit more fun and vibrant. Recently, news surfaced that this tool achieved remarkable performance improvements through the power of AI.

Why does this matter?

Most of the software we use in our daily lives is locked in a war with ‘speed.’ When a program reacts even 0.1 seconds faster, the user feels a much greater sense of comfort. TTE was previously written in Python (a programming language that is easy to learn and widely used), but Python had some limitations in terms of execution speed.

This case shows that AI can do more than just write text; it can completely rewrite existing software into a more powerful language like Rust (a programming language known for memory safety and high speed) to drastically improve performance. This hints at a new future where developers can enjoy optimal performance while reducing the burden of maintenance.

In simple terms: ‘Switching’ from Python to Rust

Let’s use a metaphor. If Python is a very comfortable ‘bicycle,’ Rust is a high-performance ‘sports car.’ A bicycle is great for a casual neighborhood ride (writing simple scripts), but it has limitations when it comes to racing on a highway (performing complex and heavy tasks).

AD

The TTE engine was previously riding that Python bicycle. However, it needed to completely replace its engine with the Rust sports car to produce more effects and move faster. This is where the AI tool ‘Fable’ stepped in. Just as a highly skilled mechanic would dismantle a bicycle and perfectly map its structure into a blueprint for a sports car, Fable analyzed the existing Python code and perfectly converted it into Rust code in a single ‘one-shot’ attempt Source 1 Source 12.

The converted program became a 3MB single file that can be executed instantly anywhere without needing Python installed, effectively eliminating concerns about dependencies (auxiliary software that must be pre-installed to run the program) Source 12.

How far have we come: How much faster is it?

The results were proven with numbers. The original Python version of TTE took 87ms (milliseconds, 1/1000th of a second) to start, but the AI-rewritten Rust version starts in just 2ms. Rendering speed (the speed at which effects are drawn on the screen) is also 9.6 times faster than before Source 1 Source 12.

Of course, TTE was already an excellent tool that worked well with only Python and no third-party modules Source 2 Source 8. However, this Rust version has made it possible to provide lighter, faster, and more immediate visual effects in the terminal environment. TTE supports over 70 visual effects, including rain, matrix, and fire, allowing users to have a colorful experience even in text-based terminals Source 5 Source 6 Source 7.

What will happen in the future?

This case is a symbolic event demonstrating the potential of ‘Code Migration’ using AI. Developers can now solve the difficult homework of performance improvement simply by feeding existing complex Python code to an AI and asking it to “optimize this in Rust.”

This is the secret behind why the apps and tools we use are becoming lighter and faster. In the future, tasks that were cumbersome and time-consuming for human developers are highly likely to be automated through AI. Beyond simple code conversion, AI is changing the very nature of software.

References

  1. DHH Shares Fable RustRewriteofPythonLibrary · Digg, https://digg.com/tech/5jmfukm3
  2. TerminalTextEffects(TTE) is a terminal visual effects engine., https://pypi.org/project/terminaltexteffects/
  3. Want Dynamic Effects for Terminal Text? X-CMD terminaltexteffects, https://www.x-cmd.com/install/terminaltexteffects
  4. Making the command line fun -terminaltexteffects- Dom Corriveau, https://blog.ctms.me/posts/2024-05-30-cli-tool-terminaltexteffects/
  5. terminaltexteffects- Inline Visual Effects in the… - Terminal Trove, https://terminaltrove.com/terminaltexteffects/
  6. GitHub - ChrisBuilds/terminaltexteffects: TerminalTextEffects (TTE) is a terminal visual effects engine, application, and Python library. · GitHub, https://github.com/ChrisBuilds/terminaltexteffects
  7. DHH on X: “Fable one-shotted a Rust rewrite of the TerminalTextEffects Python library in 11M tokens. Startup time went from 87ms to 2ms and rendering speed is up by 9.6x. Now zero dependencies and a 3mb single exec 🤯 https://t.co/3cTEQAqYdO” / X, https://x.com/dhh/status/2086590006898958752
AD
Test Your Understanding
Q1. What is the biggest change achieved as a result of this Rust rewrite?
  • Increased library size
  • Faster execution speed and a 3MB single executable file
  • Requirement to add Python modules
Through the Rust rewrite, startup time was reduced from 87ms to 2ms, rendering speed became 9.6 times faster, and it became a 3MB single executable file with zero dependencies.
Q2. What functions does TerminalTextEffects (TTE) mainly perform?
  • Web browser graphics engine
  • Generates visual effects like rain, fire, and matrix in the terminal
  • Automatic database backup
TTE is a Python-based terminal visual effects engine capable of implementing over 70 diverse effects in the terminal.
Q3. What is the name of the AI tool used in this project?
  • Fable
  • RewriteLM
  • Gemma
An AI tool called Fable used 11 million tokens to rewrite the Python library into Rust in one shot.
AI Rewrites Python Code to ...
0:00