Re:Translations of Russ Cox's Thompson NFA C Program to Rust
by muldvarp on Friday November 03, 2023 @08:45AM
(#38127887)
> * You can choose to use handles smaller than a pointer.
Did you measure any performance improvements due to using small handles?
I have a medium-sized project that uses a ton of `usize`s to reference elements in `Vec`s and would love to know if there's some potential for performance improvements there.
Re:Translations of Russ Cox's Thompson NFA C Program to Rust
by burntsushi on Friday November 03, 2023 @08:53AM
(#38127963)
In this particular program I didn't do an in depth performance comparison because it wasn't really the point of the exercise.
But in the actual regex crate, I do indeed use `u32` as a representation for a handle. To a first approximation, it corresponds to about half as much memory usage.
Same deal with the aho-corasick crate.
* You can choose to use handles smaller than a pointer.
* The NFA is cyclic, which makes memory management quite the chore. Even if you're using Rust's reference counted pointers. But if you use handles, the actual memory management becomes a lot simpler.