Skip to content
AkashPriyadarshiiPublic

Repository files navigation

ziggygrep logo: magnifier over Z

ziggygrep

Fast grep replacement in pure Zig. Literal search beats ripgrep 22 of 22 benches. Zero deps, no libc.

MIT License Zig 0.16.0 Windows, Linux, macOS

By Akash Priyadarshi · MIT · Zig 0.16.0 · zero runtime services

Why · Quickstart · Commands · Trust · Layout · Limits · Ecosystem


Direct answer

What is ziggygrep? A free, open-source grep replacement in pure Zig. You build one static binary. It searches files recursively for a literal pattern, prints path:lineno:line matches, and stays fast by skipping what cannot match before confirming what can.

Who is it for? Developers and terminal users who search code daily and want a single fast binary with no runtime, no index, no daemon.

What does it cost? Free. MIT. Zero deps, no libc, no services, no accounts.

How fast? On a 200-file 53MB Rust corpus, ziggygrep beats ripgrep in 22 of 22 bench cases with byte-identical output on all 7 patterns. Full table with rerun commands sits under Trust below.

$ ziggygrep HashMap src/
src/Args.zig:104:    var a = try testArgs(std.testing.allocator, "ziggygrep HashMap src/");
src/Args.zig:106:    try std.testing.expectEqualStrings("HashMap", a.pattern.?);
# bash/zsh (~/.bashrc or ~/.zshrc)
alias zgg='ziggygrep'
# PowerShell ($PROFILE)
Set-Alias zgg ziggygrep
:: cmd (doskey macro)
doskey zgg=ziggygrep $*

Why it earns a slot

Recursive search tools scan every byte on every query. ziggygrep cuts the cost per byte instead of indexing around it.

What you get Why it matters
One binary, zero services zig build -Doptimize=ReleaseFast. No runtime, no index build, no daemon.
Literal-first engine First-byte prefilter + eql verify, line bounding only on hits. Positions that cannot start the pattern cost one memchr step, zero slicing.
Threaded file sweep Fixed fetchAdd(8) batches from one file list, per-worker scratch buffers, files sorted at merge.
Flat memory Streaming reads, no mmap, works on pipes.
Exit codes pipelines respect 0 match found, 1 no match, 2 usage or I/O error.

Quickstart

git clone https://github.com/AkashPriyadarshii/ziggygrep.git
cd ziggygrep
zig build -Doptimize=ReleaseFast

Binary: zig-out/bin/ziggygrep (ziggygrep.exe on Windows).

# Search current directory recursively
ziggygrep HashMap .

# Search one file
ziggygrep TODO src/main.zig

# Files with matches only
ziggygrep -l HashMap .

# Counts per file
ziggygrep -c HashMap .

Command Reference

Short Long Effect
-l --files-with-matches Print only file names with matches
-c --count Print match counts per file
-M N --max-columns N Truncate lines longer than N columns (0 disables)
-h --help Usage
-V --version Version

How far to trust it

Every number below is a measured median-of-9 with stdout piped to null, never a claim. 22 of 22 cases at or below ripgrep. 7 of 7 patterns byte-identical.

Pattern Full (PATTERN .) -c counts -l files-only
he 38ms vs 44ms 28ms vs 35ms 17ms vs 21ms
in 85ms vs 96ms 40ms vs 55ms 17ms vs 20ms
HashMap 37ms vs 40ms 33ms vs 43ms 16ms vs 20ms
pub fn 66ms vs 92ms 33ms vs 54ms 15ms vs 23ms
x 66ms vs 105ms 33ms vs 51ms 19ms vs 20ms
fn 79ms vs 110ms 38ms vs 55ms 15ms vs 20ms
e 87ms vs 102ms 31ms vs 48ms 15ms vs 18ms
Miss (ZZZNOMATCHXYZ) 24ms vs 24ms tie - -

Each cell reads ziggygrep ms vs rg ms. Rerun any cell: ziggygrep [-c|-l] PATTERN . > /dev/null against rg --no-config -F --no-heading --line-number [-c|-l] PATTERN . > /dev/null.

Check Result Rerun
Parity he 112051/112051 lines match rg -F tools/normcmp.py
Parity in 600000/600000 tools/normcmp.py
Parity HashMap 112426/112426 tools/normcmp.py
Parity pub fn 600000/600000 tools/normcmp.py
Parity x 600000/600000 tools/normcmp.py
Parity fn 600000/600000 tools/normcmp.py
Parity e 561539/561539 tools/normcmp.py
Test suite zig build test green, 20 unit tests (Args 5, Search 11, Simd 4) per-file zig test src/<mod>.zig

Method: 200-file 53MB Rust corpus, ReleaseFast binary (x86_64-v3/AVX2), stdout piped to null, median-of-9, Windows MSYS2. rg 15.2.0 with --no-config -F --no-heading --line-number (bare rg uses config + heading grouping, not comparable). Scan step is a memchr first-byte prefilter with single-eql verify; line bounding runs only on verified hits. Speedups are ratios of medians on that fixture; your disk and cache shape your numbers.


Architecture

  • Literal scan, no regex engine. First-byte prefilter, line bounding on hits only, eql confirm. Same-line hits deduped, finished lines jumped past.
  • Thread pool over files. Fixed batches, per-worker scratch/carry/chunk buffers, deterministic file-sorted merge. Lists of 8 or fewer files run direct, no spawn.
  • Buffered stdout. 256KB accum, one flush, pipe-safe 60KB chunks.
  • No mmap. Streaming I/O keeps memory flat and works on pipes.
src/
  main.zig    - entry point, error handling, exit codes
  Args.zig    - CLI argument parsing (+ unit tests)
  Walk.zig    - recursive walk, dotfile skip, 4KB path arena
  Search.zig  - literal line scan (+ unit tests)
  Simd.zig    - rarity table + pair picker, kept for long-line corpora (+ unit tests)
  Engine.zig  - batch index, fused scan+format, sorted merge
  Out.zig     - output formatting, buffered writes
  Io.zig      - raw syscalls, no-libc read/write
build.zig     - Zig build script
build.zig.zon - package metadata

Development

zig build test

Tests live beside the code they cover. Non-trivial logic ships with one runnable check. Keep diffs small: stdlib before deps (there are no deps).


Limits and non-goals

  • No regex. Patterns are literal bytes. Use ripgrep when you need regex.
  • No .gitignore parsing in v0.1. Dotfiles and .git are skipped; full ignore support is planned.
  • No colors, no context flags, no JSON output in v0.1.
  • No index, no daemon, no background services. Every query scans. That is the design.
  • Not a pager. Pipe to less when you want paging.

Frequently Asked Questions

What is ziggygrep?

ziggygrep is a high-speed literal text search CLI written in pure Zig. It searches files and directories recursively for literal strings and prints path:lineno:line matches, compiled as a standalone static binary with zero external dependencies and no libc.

How does ziggygrep beat ripgrep on literal search?

ziggygrep uses a literal-first search pipeline: a first-byte SIMD prefilter (memchr skipping 32 bytes/step) combined with a single slice verification (std.mem.eql). Line bounding, parsing, and formatting run exclusively on confirmed matches rather than every line. In benchmark runs across 200 files (53MB corpus), ziggygrep outpaced ripgrep in 22 of 22 test cases with byte-identical output.

When should I use ripgrep instead?

Use ripgrep when you require full regular expressions, PCRE2 syntax, complex .gitignore filtering, or multiline regex patterns. ziggygrep is dedicated to literal needle searches where raw throughput and minimal overhead matter most.


Ecosystem


Author

MIT. Built by Akash Priyadarshi (Patna, Bihar, India).

Social: X/Twitter · Threads · Instagram · Reddit


Contributors

PRs welcome. Keep it boring: smallest diff that holds, stdlib before deps (there are no deps), one runnable check for non-trivial logic. Run zig build test before you push.


One static binary. Zero services. Finds needles fast.

Releases

Packages

Contributors

Languages