百科.dev
全部条目AI 编程趋势榜开源项目技术资讯提交条目
登录
< 返回工具列表
S

StringZilla

> 数据库
开源

针对 C、C++、CUDA、Python、Rust、Swift、JS 和 Go 语言,利用 NEON、AVX2、AVX-512、SVE、GPGPU 和 SWAR 等技术,可将字符串处理速度提高 100 倍,从而加速搜索、哈希、排序等操作。

3.5K stars0 点赞0 次浏览
访问官网GitHub

工具介绍

针对 C、C++、CUDA、Python、Rust、Swift、JS 和 Go 语言,利用 NEON、AVX2、AVX-512、SVE、GPGPU 和 SWAR 等技术,可将字符串处理速度提高 100 倍,从而加速搜索、哈希、排序等操作。

StringZilla

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.

  • It can be 3x faster than LibC doing substring search on Arm servers, and 9x on Apple Silicon, where the system strstr is weaker.
  • It can be 10-70x faster than ICU, both ICU4C and its Rust successor ICU4X, in UTF-8 handling, case folding, segmentation, and tokenization.
  • It can be over 10x faster than NVIDIA's own libraries for on-GPU Levenshtein, NW, and SW edit distances.
  • It comes with built-in custom WebAssembly backend for sandboxed browser, DBMS, & LLM environments, custom RVV backend for RISC-V CPUs, PowerPC backend for IBM Power servers, LoongArch for Chinese domestic chips, and more!

Reach for it from your language of choice:

  • C: Upgrade LibC's <string.h> to <stringzilla/stringzilla.h> in C 99
  • C++: Upgrade STL's <string> to <stringzilla/stringzilla.hpp> in C++ 11
  • CUDA: Process in-bulk with <stringzillas/stringzillas.cuh> in CUDA C++ 17
  • Python: Upgrade your str to faster Str
  • Rust: Use the StringZilla traits crate
  • Go: Use the StringZilla cGo module
  • Swift: Use the String+StringZilla extension
  • JavaScript: Use the StringZilla library
  • C#: Zero-copy over ReadOnlySpan<byte>, NativeAOT-friendly
  • ☕ Java: Pure FFM API over MemorySegment, no JNI
  • [Shell][faq-shell]: Accelerate common CLI tools with sz- prefix
  • Researcher? Jump to Algorithms & Design Decisions
  • Thinking to contribute? Look for ["good first issues"][first-issues]
  • And check the guide to set up the environment
  • Want more bindings or features? Let me know!

Who is this for?

  • For data-engineers parsing large datasets, like the CommonCrawl, RedPajama, or LAION.
  • For software engineers optimizing strings in their apps and services.
  • For bioinformaticians and search engineers looking for edit-distances for USearch.
  • For [DBMS][faq-dbms] devs, optimizing LIKE, ORDER BY, and GROUP BY operations.
  • For hardware designers, needing a SWAR baseline for string-processing functionality.
  • For students studying SIMD/SWAR applications to non-data-parallel operations.

Performance

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. Xeon4 is an Intel Sapphire Rapids with GCC and glibc, M5 Pro an 18-core Apple Silicon with Apple clang and libc++, H100 an Nvidia Hopper GPU. The two CPUs therefore differ in standard library as much as in ISA, which is most of the gap in the strstr, std::string::rfind, and bytes.translate rows; 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.

Why StringZilla

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.

…

Functionality

StringZilla is compatible with most modern CPUs, and provides a broad range of functionality. It's split into 2 layers:

  1. StringZilla: single-header C library and C++ wrapper for high-performance string operations.
  2. StringZillas: parallel CPU/GPU backends used for large-batch operations and accelerators.

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:

  • across both little-endian and big-endian architectures.
  • across 32-bit and 64-bit hardware architectures.
  • across operating systems and compilers.
  • across ASCII and UTF-8 encoded inputs.

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.

Quick Start

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.

Python

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.

C and C++

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.

Rust

cargo add stringzilla · guide

Issues· 30 开放

查看全部 Issues在 GitHub 打开

暂无开放 Issues,或尚未同步最近议题。

> 标签

Cdatasetedit-distancegpuhash

暂无评论,来聊聊你的看法吧

> 工具信息

发布日期2026年8月1日
最后更新2026年9月17日
分类数据库
定价开源

> 相关工具

P
PostgreSQL
功能强大的开源关系型数据库
R
Redis
内存数据结构存储,常用作缓存与队列
M
MySQL
广泛使用的开源关系型数据库