Dan-wanna-M / kbnf

A fast constrained decoding engine based on context free grammar in Rust
Other
2 stars 0 forks source link

Eager token id cache for regular expressions #1

Open Dan-wanna-M opened 1 month ago

Dan-wanna-M commented 1 month ago

Currently, only lazy cache is supported. This means the first run of an engine is never accelerated by cache. Combined with grammar rules that accept large numbers of tokens, this could make the engine slow. While I cannot figure out a good eager cache strategy for context free grammars, caching regular expressions(which are already fully compiled into DFAs) should be very easy. Some extra efforts probably are necessary for caching tokens that cross the boundary of regular expressions and ordinary context free grammar rules.

Once this is done, stronger claims can be made for time complexity. What's more, the speed of directly generating context free grammar will not be practically inferior to generating regular expressions.