{"by":"matthewolfe","descendants":73,"id":44422480,"kids":[44422888,44422818,44423489,44425827,44424134,44425649,44423369,44423436,44423338,44439670,44422939,44423953,44424452,44423337,44427659,44425100,44428396,44430975,44423793,44427754,44424606,44423997,44426178,44423620],"score":281,"text":"TokenDagger is a drop-in replacement for OpenAI’s Tiktoken (the tokenizer behind Llama 3, Mistral, GPT-3.*, etc.). It’s written in C++ 17 with thin Python bindings, keeps the exact same BPE vocab&#x2F;special-token rules, and focuses on raw speed.<p>I’m teaching myself LLM internals by re-implementing the stack from first principles. Profiling TikToken’s Python&#x2F;Rust implementation showed a lot of time was spent doing regex matching. Most of my perf gains come from a) using a faster jit-compiled regex engine; and b) simplifying the algorithm to forego regex matching special tokens at all.<p>Benchmarking code is included. Notable results show:\n- 4x faster code sample tokenization on a single thread.\n- 2-3x higher throughput when tested on a 1GB natural language text file.","time":1751286838,"title":"Show HN: TokenDagger – A tokenizer faster than OpenAI's Tiktoken","type":"story","url":"https://github.com/M4THYOU/TokenDagger"}