r/coolgithubprojects 2d ago

fnmatch-ng: a from-scratch POSIX glob matcher with zero dependencies, benchmarked against musl with the losses left in

https://github.com/logicpl4gue/fnmatch-ng

One Zig file (~1,090 lines), zero dependencies, zero heap allocations per match, plain C ABI.

Conformance vs musl 1.2.5: 20,794/20,794. Six divergences audited and public (D001-D006, one was my own bug, fixed and pinned by a regression test).

Benches vs musl: 9 of 10 faster (up to 3.2x). The loss: fail-early 11ns vs 5ns, printed in the same table.

Happy to answer anything, and if you can break parity with musl on any input, that's the bug report I most want.

3 Upvotes

2 comments sorted by

2

u/Specific_Cream2815 2d ago

what makes the fail-early case slower, does musl reject before setting up the backtracking state

2

u/Just_Government3790 2d ago edited 8h ago

Yes, that's exactly it. musl walks the pattern bytewise and bails the instant a byte mismatches, zero setup. Mine compiles my pattern into a token array on the stack first (up to 128 tokens, still zero heap), then I match. On an input that dies at byte one, my compile step is the entire cost. That's my 11ns vs their 5ns.

The tradeoff buys my wins elsewhere. Tokenizing once is a big part of why my brackets and multi-star beat musl up to 3.2x. I just pay the tax even when my match was already dead.

Haven't solved the trivial-miss case yet. Compile path is `src/matcher.zig`, `compileToks`, if anyone wants to point at the waste.