lemmeknow icon indicating copy to clipboard operation
lemmeknow copied to clipboard

use `onig` crate for matching on strings

Open swanandx opened this issue 3 years ago • 0 comments

We can use onig crate instead of regex crate for strings API. We can't fully replace regex crate as onig doesn't provide a way to match on bytes not it compiles for wasm32 ( it might, but that will be lot of work ).

Suggestion

  • Use onig for matching on strings ( not on wasm32 target )
  • Use regex for bytes and strings for wasm32

Pros

  • onig takes performance from 130ms to 28ms!! It's blazingly fast

Cons

  • Variance in performance for matching on strings and bytes for API users, because we have no other choice than using regex crate for bytes
  • Extra dependency

Workaround

  • We can make a feature called bytes for enabling bytes support, that way users can explicitly opt for adding regex crate as dependency and be aware of slower ( comparatively ) performace.

regex vs onig crate benchmark!

image

swanandx avatar Aug 16 '22 17:08 swanandx