针对 C、C++、CUDA、Python、Rust、Swift、JS 和 Go 语言,利用 NEON、AVX2、AVX-512、SVE、GPGPU 和 SWAR 等技术,可将字符串处理速度提高 100 倍,从而加速搜索、哈希、排序等操作。
针对 C、C++、CUDA、Python、Rust、Swift、JS 和 Go 语言,利用 NEON、AVX2、AVX-512、SVE、GPGPU 和 SWAR 等技术,可将字符串处理速度提高 100 倍,从而加速搜索、哈希、排序等操作。
Strings are the first fundamental data type every programming language implements in software rather than hardware — the closest CPUs come to a "find substring" instruction is x86's PCMPISTRI, which is too slow and too narrow to build a library on, and nothing ships a "compute string hash" instruction at all.
So most string-processing code still looks like for (i = 0; i < length; ++i) if (text[i] == 'x') … — a tangle of loops, branches, and per-character lookups, where the surrounding control flow often costs more than the character-level logic itself, whether the text is ASCII or UTF-8 encoded Unicode.
Worse, chewing through one byte or codepoint at a time squanders the hardware: a modern CPU carries dozens of 16-64 byte architectural registers, and hundreds of physical ones to feed out-of-order execution.
StringZilla reaches for those [SIMD][faq-simd] and [SWAR][faq-swar] instructions directly, offering one of the widest, fastest, and most portable collections of text-processing primitives anywhere.
StringZilla is the GodZilla of string libraries, accelerating exact and fuzzy matching, hashing, edit distances, sorting, segmentation, and even random-string generation, with allocation-free lazily-evaluated iterators throughout.
strstr is weaker.Reach for it from your language of choice:
<string.h> to <stringzilla/stringzilla.h> in C 99<string> to <stringzilla/stringzilla.hpp> in C++ 11<stringzillas/stringzillas.cuh> in CUDA C++ 17str to faster StrStringZilla traits crateStringZilla cGo moduleString+StringZilla extensionStringZilla libraryReadOnlySpan<byte>, NativeAOT-friendlyMemorySegment, no JNIsz- prefixWho is this for?
LIKE, ORDER BY, and GROUP BY operations.Throughput and timings on two CPUs and one GPU, grouped by operation.
Only the languages that ship a counterpart appear under each heading.
StringZilla.C is the C kernel called directly; StringZilla.Py is the same kernel through the CPython binding, so the gap between them is the cost of crossing the interpreter boundary.
…
Treat these as a first impression, not a benchmark suite. The Unicode numbers were obtained on a 128 MB slice of multilingual XLSum; the similarity rows on synthetic DNA strings.
Xeon4is an Intel Sapphire Rapids with GCC andglibc,M5 Proan 18-core Apple Silicon with Apple clang andlibc++,H100an Nvidia Hopper GPU. The two CPUs therefore differ in standard library as much as in ISA, which is most of the gap in thestrstr,std::string::rfind, andbytes.translaterows; the StringZilla rows build from the same source on both. These will not reproduce exactly; the links below carry the methodology and the per-library breakdowns.
Most StringZilla modules ship ready-to-run benchmarks for C, C++, Python, and more.
Grab them from ./scripts, and see CONTRIBUTING.md, test/README.md, and bench/README.md for instructions.
For wider head-to-heads against Rust and Python favorites, browse the StringWars repository.
To inspect collision resistance and distribution shapes for our hashers, see HashEvals.
There are several other excellent libraries with overlapping subsets of operations and somewhat different design philosophies. LibC obviously provides a good baseline for basic memory operations, but its APIs vary widely in quality, and its Arm implementations often trail its x86 ones. ICU and ICU4X implement the Unicode standard to a letter, but don't exploit hidden invariants in the Unicode ruleset to vectorize those operations. RapidFuzz comes with a very good set of string-similarity algorithms and is already well vectorized on CPUs, but leaves batched cross-products symmetries and massive GPU speedups on the table. xxHash and aHash provide great non-cryptographic hashes, but may not cover all of the hashing use cases, or leverage the wider AES and predicated instructions available on modern CPUs.
Because StringZilla mirrors the familiar standard APIs, adoption is mostly a search-and-replace.
…
StringZilla is compatible with most modern CPUs, and provides a broad range of functionality. It's split into 2 layers:
Having a second C++/CUDA layer greatly simplifies the implementation of similarity scoring and fingerprinting functions, which would otherwise require too much error-prone boilerplate code in pure C. Both layers are designed to be extremely portable:
Not all features are available across all bindings. Consider contributing if you need a feature that's not yet implemented.
| Maturity | C | C++ | Python | Rust | JS | Swift | Go | C# | Java | |
|---|---|---|---|---|---|---|---|---|---|---|
| Substring Search | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Character Set Search | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Sorting & Sequence Operations | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ⚪ | ✅ | ✅ | |
| Set Intersection & Joins | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ⚪ | ✅ | ✅ | |
| Lazy Ranges, Compressed Arrays | ❌ | ✅ | ✅ | ✅ | ❌ | ⚪ | ⚪ | ✅ | ✅ | |
| One-Shot & Streaming Hashes | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Cryptographic Hashes | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Small String Class | ✅ | ✅ | ❌ | ⚪ | ❌ | ❌ | ❌ | ❌ | ❌ | |
| Random String Generation | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ⚪ | ✅ | ✅ | |
| Unicode Case Folding | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Uncased UTF-8 Search | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| TR29 Word Boundary Detection | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ⚪ | ✅ | ✅ | |
| TR29 Grapheme Segmentation | ✅ | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ✅ | ✅ | |
| TR29 Sentence Segmentation | ✅ | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ✅ | ✅ | |
| UAX14 Line-Break Detection | ✅ | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ✅ | ✅ | |
| Unicode Normalization | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Codepoint Counting & Indexing | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | |
| Parallel Similarity Scoring | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ⚪ | ⚪ | ⚪ | |
| Parallel Rolling Fingerprints | ✅ | ✅ | ✅ | ✅ | ⚪ | ⚪ | ⚪ | ⚪ | ⚪ |
parts are used in production. parts are in beta. parts are under active development, and are likely to break in subsequent releases. ✅ are implemented. ⚪ are considered. ❌ are not intended.
Each binding has its own install command, import line, and dedicated guide, all collected in the per-language sections below.
The batch and GPU engines ship separately, as stringzillas-cpus and stringzillas-cuda on PyPI and the cpus and cuda crate features; each binding's guide covers the details.
pip install stringzilla · guide: python/README.md
import stringzilla as sz
text = sz.Str("the quick brown fox")
text.find("brown") # 10
text.split() # Strs(['the', 'quick', 'brown', 'fox'])
sz.hash("hello") # fast 64-bit hash
The Python package upgrades str and bytes with SIMD search, sorting, hashing, UTF-8 segmentation, and Unicode case-folding, plus the batch-parallel stringzillas engines for edit distances and rolling fingerprints.
Header-only, or pull it in with CMake FetchContent, or find_package(stringzilla) an installed build · guides: include/stringzilla/README.md and include/stringzillas/README.md
#include <stringzilla/stringzilla.h>
sz_find(haystack, h_length, "brown", 5); // pointer to the match, or NULL
#include <stringzilla/stringzilla.hpp>
namespace sz = ashvardanian::stringzilla;
sz::string_view("the quick brown fox").find("brown"); // 10
The header-only library covers search, hashing, sorting, comparison, set intersection, memory operations, and lazy UTF-8 segmentation; the bulk and GPU engines for edit distances, alignment scores, and fingerprints live in the companion stringzillas distribution.
cargo add stringzilla · guide
暂无开放 Issues,或尚未同步最近议题。