#ansi-escapes #performance-optimized #sequence #stripper #low-allocation

fast-strip-ansi

A performance-optimized, low-allocation ANSI escape sequence stripper

19 releases (8 breaking)

Uses new Rust 2024

0.11.0 Oct 7, 2025
0.9.4 Oct 6, 2025

#11 in #performance-optimized

Download history 218/week @ 2025-08-25 41/week @ 2025-09-01 352/week @ 2025-09-08 179/week @ 2025-09-15 8/week @ 2025-09-22 10/week @ 2025-09-29 1817/week @ 2025-10-06 106/week @ 2025-10-13 5/week @ 2025-10-20 10/week @ 2025-10-27 70/week @ 2025-11-03 71/week @ 2025-11-10 252/week @ 2025-11-17 206/week @ 2025-11-24 61/week @ 2025-12-01

596 downloads per month
Used in 5 crates (4 directly)

Apache-2.0 OR MIT

135KB
3K SLoC

fast-strip-ansi

A performance-optimized ANSI escape sequence stripper, built on top of the vt-push-parser crate.

Full VT-100/ANSI support.

No startup cost for regex compilation.

Usage

use fast_strip_ansi::*;
let input = b"Hello, world!\x1b[31m\nHello, world!\x1b[0m";
assert_eq!(strip_ansi_bytes(input), b"Hello, world!\nHello, world!".as_slice());
let input = "Hello, world!\x1b[31m\nHello, world!\x1b[0m";
assert_eq!(strip_ansi_string(input), "Hello, world!\nHello, world!");

Security and Correctness

fast-strip-ansi is correct and secure. It contains a true VT-100/ANSI state machine which handles corner cases not handled by other crates.

Performance

fast-strip-ansi the fastest and most correct library for stripping ANSI escape sequences.

Note that fast-strip-ansi has wider support for ANSI escape sequences than most crates but is still the fastest option.

It is significantly faster than strip-ansi and strip-ansi-escapes in all modes.

xychart
    title "Performance"
    x-axis [fast-strip-ansi, fast-strip-ansi-callback, strip-ansi, strip-ansi-escapes]
    y-axis "Time (in µs)" 0 --> 100
    bar [22.12, 11.26, 39.05, 292.5]
    bar [11.89, 6.841, 19.21, 277.4]

%% Your markdown viewer may not render the chart correctly.
%% View in a mermaid chart viewer like <https://mermaid.live>

Raw performance data:

from cargo bench on an M3 MacBook Pro

0 suffix means no ansi content, 100 means significant ansi content

comparison fastest median
fast_strip_ansi_crate_0 6.54 µs 6.937 µs
fast_strip_ansi_crate_100 18.7 µs 19.14 µs
fast_strip_ansi_crate_bytes_0 6.624 µs 6.707 µs
fast_strip_ansi_crate_bytes_100 10.83 µs 10.95 µs
fast_strip_ansi_crate_callback_0 6.333 µs 6.416 µs
fast_strip_ansi_crate_callback_100 10.37 µs 10.66 µs
strip_ansi_crate_0 15.33 µs 15.95 µs
strip_ansi_crate_100 23.54 µs 26.47 µs
strip_ansi_escapes_crate_0 235.9 µs 257.9 µs
strip_ansi_escapes_crate_100 241.8 µs 269.1 µs

Crate versions:

crate version
fast-strip-ansi latest
strip-ansi 0.1.0
strip-ansi-escapes 0.2.1

Dependencies

~100KB