pandaman64/lean-regex

Caching

Opened this issue · 1 comments

The rust regex library uses caching for improving a little bit the performance. I think that we could add something for it.

For those who are interested in shaving off unnecessary allocations:

  • NFA.captureNext discards the sparse sets and saveSlots every time it's called, which can be reused across the calls
  • Also, I think it's initSave reallocates an empty array due to the dependency on saveSize. We should allocate it once for one captureNext call (ideally once for each size).
  • (Difficult) I believe Option Pos incurs a heap allocation. Since the string length is bounded in practice, we can embed .none into Pos and just use usize under the food.

I'd recommend #11 first though so that we have a benchmark to measure the effect of the optimizations.