# New Compaction-based Zig Tokenizer

**URL:** <https://ziggit.dev/t/new-compaction-based-zig-tokenizer/9661>\
**Category:** Showcase\
**Tags:** language, compiler\
**Created:** [April 16, 2025, 12:39pm UTC](https://ziggit.dev/t/new-compaction-based-zig-tokenizer/9661 "2025-04-16T12:39:19Z")\
**Posts on this page:** 1\
**Showing post:** 17

<div class="post-metadata">

**Author:** ![breadtom](https://ziggit.dev/letter_avatar_proxy/v4/letter/b/43a26b/32.png) [@breadtom](https://ziggit.dev/u/breadtom)\
**Post date:** [April 20, 2025, 5:11pm UTC](https://ziggit.dev/t/new-compaction-based-zig-tokenizer/9661/17 "2025-04-20T17:11:16Z")

</div>

I do have a [similar project](https://codeberg.org/breadtom/expozig), inspired from [your work](https://ziggit.dev/t/building-self-hosted-from-the-original-c-implementation/6607). One function you optimize on all three compilers is the `getKeyword()`. Instead of [strncmp for loop every keyword](https://git.jakstys.lt/motiejus/zig0/src/commit/d22667f79ae8e9aa964cd22a4a8fdd333fab3157/tokenizer.c#L76), replace it with a [switch on keyword length, then memcmp the string.](https://codeberg.org/breadtom/expozig/src/commit/bc49d81a73abe4bf9ee8d5a6a6370aa088ac6dd9/src/stage1/tokenizer.c#L6). It made GCC 14 go from 22 ms to 10.5 ms. TCC 0.9.27 went from around 35 ms to 22 ms. Clang 19 stayed the same at around 7.5 ms. All reading from Zig 0.14 src/Sema.zig

---

_[View the full topic](https://ziggit.dev/t/new-compaction-based-zig-tokenizer/9661)._
