⚡ Minimal, deterministic, zero-dependency tokenization engine for code analysis, syntax highlighting, and LLM text pipelines. Operates in
FastTokenize is a high-performance, zero-dependency Java tokenization library and part of the FastJava ecosystem. It provides dedicated scanners for 10+ programming languages and formats, outputting structured token streams and zero-allocation byte arrays for FastTerminal and terminal text applications.
Watch Demo (YouTube) | Watch JMH Benchmark (YouTube)
import fasttokenize.FastTokenize;
import fasttokenize.Language;
import fasttokenize.Token;
import fasttokenize.TokenType;
import fastterminal.FastTerminalScene;
public class TerminalSyntaxRendererDemo {
public static void renderCodeLine(FastTerminalScene scene, String filename, String lineText, int lineY) {
// 1. Instantly tokenize line into zero-allocation style/type IDs
byte[] typeIds = FastTokenize.tokenizeStyles(Language.fromFilename(filename), lineText);
// 2. Direct cell-by-cell write into FastTerminal double-buffered scene
for (int col = 0; col < lineText.length(); col++) {
int codePoint = lineText.codePointAt(col);
byte typeId = typeIds[col];
// Resolve color palette from TokenType ID
int fgColor = resolveColorForType(typeId);
int bgColor = -2; // Transparent background
scene.writeCell(col, lineY, codePoint, fgColor, bgColor);
}
}
private static int resolveColorForType(byte typeId) {
return switch (TokenType.values()[typeId]) {
case KEYWORD -> 0x569CD6; // Blue
case STRING -> 0xCE9178; // Orange/Brown
case NUMBER -> 0xB5CEA8; // Light Green
case COMMENT -> 0x6A9955; // Dark Green
case ANNOTATION -> 0x4EC9B0; // Cyan
default -> 0xD4D4D4; // Default Text
};
}
}- Why FastTokenize?
- Key Features
- Real-World Use Cases
- Performance Benchmarks
- Supported Languages
- Installation
- Documentation
- Platform Support
- License
- Related Projects
Traditional syntax highlighters and code tokenizers are poorly suited for real-time terminal editors and low-latency text pipelines:
- Regex Backtracking & CPU Spikes: Conventional highlighters (like RSyntaxTextArea) run multiple regex passes per line, triggering catastrophic backtracking and CPU spikes on dense files.
- Heavy AST Heap Bloat: Full language parsers like Tree-sitter or ANTLR instantiate deep syntax trees, creating heavy JVM heap churn and GC pauses during fast scrolling.
- Slow Line Re-Tokenization: Interactive terminal editors require sub-millisecond per-line token styling; heavy parsers require multi-pass passes that stall the render loop.
- Complex Native & Grammar Dependencies: Solutions like Tree-sitter require platform-specific compiled C libraries for each grammar, complicating deployment.
FastTokenize resolves these issues with dedicated deterministic scanners and compact byte outputs:
-
$O(n)$ Single-Pass Scanning: Scans source code in microseconds with zero backtracking and deterministic linear complexity. -
Zero-Allocation Style Byte Streams: Generates compact
byte[]style IDs matching character offsets, directly consumable byFastTerminaland TUIs. - Microsecond Tokenization Latency: Processes files in ~5.4 µs (>183,000 tokenizations/sec) to maintain effortless 60+ FPS viewport rendering.
- Zero Dependencies: Lightweight standalone JAR (<50 KB) with dedicated scanners for 10+ languages and zero native binary requirements.
| Feature | Regex Highlighters (RSyntaxTextArea) | Full AST Parsers (Tree-sitter / ANTLR) | FastTokenize |
|---|---|---|---|
| Parsing Model | Multi-pass Regex matching | Full LALR / GLR syntax tree |
|
| Tokenization Speed | 150–800 µs / line | 2–10 ms (Full tree parse) | ~5.4 µs / file (>183,000 ops/s) |
| Heap Memory Overhead | Regex Matcher & String churn | Deep AST node trees on heap | Zero-allocation byte[] style stream |
| Terminal / TUI Synergy | ❌ Complex token conversion | ✅ Direct cell-by-cell styling for FastTerminal
|
|
| Dependency Footprint | Java regex engine | Heavy C libraries / Grammar JARs | Zero dependencies (< 50 KB pure Java) |
| 60 FPS Viewport Sync | ❌ Stalls real-time render loops | ✅ Flawless 60+ FPS terminal sync |
- 🚀 Ultra-Fast Tokenization — Process large source files in microseconds with minimal CPU usage.
- 🎨 10+ Supported Languages — Dedicated scanners for Java, C/C++, Python, C#, JS/TS, JSON, CSS, XML, and Markdown.
- 🖌️ Direct Terminal Style Integration — Native byte-array style output for zero-copy terminal rendering.
- 📂 Comprehensive Test Corpus — Fully validated against a complete language spectrum in
docs/samples.
- 🧭 CreamCLI Next-Gen Terminal Editor: Power 60+ FPS zero-latency syntax highlighting and code line rendering in CreamCLI without JVM Garbage Collection stalls.
- 🤖 FastAI & LLM Code Prompting: Tokenize and filter code snippets into structured Token Streams before feeding them to local or cloud LLM models.
- 🔍 High-Speed Code Search & Indexing: Extract method identifiers, classes, and annotations for instant indexing in
FastFileContentIndexwhile skipping comments and strings. - 📄 Terminal File Previews: Generate instant colored ANSI / TUI previews for large source code files in
FastTerminaland TUI dashboards.
FastTokenize is built for high-throughput code tokenization and zero-copy terminal rendering. In the official JMH Benchmark, the system measured throughput across 180+ byte source snippets:
Benchmark Mode Cnt Score Error Units
TokenizerBenchmark.benchmarkCppTokenization thrpt 5 183690.846 ± 259902.107 ops/s
TokenizerBenchmark.benchmarkJavaStyleByteStream thrpt 5 72195.332 ± 30698.835 ops/s
TokenizerBenchmark.benchmarkJavaTokenization thrpt 5 85806.426 ± 48010.356 ops/s
183,000 Tokenizations per Second:
FastTokenizeparses source code files and outputs zero-allocation style byte arrays in ~5.4 microseconds per file.
| Language / Format | Extensions | Dedicated Scanner | Key Constructs Handled |
|---|---|---|---|
| Java / Kotlin | .java, .kt |
JavaScanner |
Javadoc, Annotations (@Override), Generics, Literals |
| C / C++ | .c, .cpp, .h, .hpp |
CppScanner |
Preprocessor (#include, #define), Intrinsics, Namespaces |
| Python | .py, .pyw, .pyi |
PythonScanner |
Triple Quotes ("""), Decorators (@property), Raw Strings |
| C# (.NET) | .cs, .csx |
CSharpScanner |
Verbatim (@""), Interpolation ($""), Attributes, Async |
| JS / TS / JSX | .js, .ts, .jsx, .tsx |
CppScanner |
Template Literals, React Components, Arrow Functions |
| JSON | .json |
JsonScanner |
Property Keys ("key":) vs Values, Exponents, Booleans |
| CSS / SCSS | .css, .scss, .less |
CssScanner |
At-Rules (@media), Selectors (.class, #id), Variables |
| XML / HTML | .xml, .html, .svg |
XmlScanner |
Directives (<?xml?>), Tags, Attributes, Comments (<!-- -->) |
| Markdown | .md, .markdown |
MarkdownScanner |
Headers (#), Fenced Code Blocks (```), Links |
Add the JitPack repository and dependency to your pom.xml:
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastTokenize</artifactId>
<version>0.1.0</version>
</dependency>
<!-- Hardware acceleration & native JNI dependencies -->
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastCore</artifactId>
<version>0.1.0</version>
</dependency>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastSIMD</artifactId>
<version>0.1.3</version>
</dependency>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastPointer</artifactId>
<version>0.1.1</version>
</dependency>
<dependency>
<groupId>com.github.andrestubbe</groupId>
<artifactId>FastMemory</artifactId>
<version>0.1.1</version>
</dependency>
</dependencies>repositories {
maven { url 'https://jitpack.io' }
}
dependencies {
implementation 'com.github.andrestubbe:FastTokenize:0.1.0'
implementation 'com.github.andrestubbe:FastCore:0.1.0'
implementation 'com.github.andrestubbe:FastSIMD:0.1.3'
implementation 'com.github.andrestubbe:FastPointer:0.1.1'
implementation 'com.github.andrestubbe:FastMemory:0.1.1'
}Download the latest JARs directly to add them to your classpath:
- ⚡ FastTokenize-0.1.0.jar (Tokenization Engine)
- ⚙️ fastcore-0.1.0.jar (Unified Native JNI Loader)
- 🚀 FastSIMD-0.1.3.jar (Hardware Vector Engine)
- 📌 FastPointer-0.1.1.jar (Native Off-Heap Memory Pointer)
- 💾 FastMemory-0.1.1.jar (Aligned Native Allocator)
Important
FastTokenize integrates FastCore, FastSIMD, FastPointer, and FastMemory for 100% hardware-accelerated AVX2 SIMD scanning and zero-copy aligned off-heap memory processing.
- Language Test Corpus — Complete spectrum of reference test files for all supported languages.
-
PHILOSOPHY.md — Engineering rationale for
$O(n)$ zero-allocation tokenization. - ROADMAP.md — Future milestones and C++/AVX2 SIMD native bridge plans.
| Platform | Status |
|---|---|
| Windows 10/11 | 🚀 Fully Supported |
| Linux | 🚀 Fully Supported |
| macOS | 🚀 Fully Supported |
MIT License — see LICENSE for details.
- Cream-CLI — Next-generation command-line workspace (Terminal + File Explorer + AI Shell).
- FastTerminal — High-performance double-buffered TUI terminal engine.
- FastFileIndex — Native mmap file indexing engine.
- FastCore — Unified JNI loader and platform abstraction.
Part of the FastJava Ecosystem
Making the JVM faster. Small package. Maximum speed. Zero bloat. 🚀
