Turnerj / Quickenshtein

Making the quickest and most memory efficient implementation of Levenshtein Distance with SIMD and Threading support

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Identify "slowdown" with one of the two strings being empty

Turnerj opened this issue · comments

This "slowdown" is very small - like 10 to 13 nanoseconds however it is more the big difference between it and Fastenshtein for the same fundamental logic.

Fastenshtein

  • Blank source and target (2.2 ns)
  • 10 character source and blank target (2.2 ns)
  • Blank source and 10 character target (15.8 ns) (This path doesn't apply shortcuts)

Quickenshtein

  • Blank source and target (13.6 ns)
  • 10 character source and blank target (13.6 ns)
  • Blank source and 10 character target (13.6 ns)

In each one for Quickenshtein, I'm only doing one or two if-statements and returning a result. My theory is it might be a code-size/CPU cache issue.

The reason to even identify this isn't so much about saving 11 nanoseconds on the same operation, it is understand why there would be a difference in the first place.

It does seem to be a code-size/cache issue - commenting out calls after the specific if-statements makes the statements run faster. The main slowdown is actually the CalculateDistance method, likely from all the crazy inlined code.

With a big internal refactor, the time has been significantly reduced to be within a nanosecond or two of Fastenshtein.