perf: Optimize and reduce size of StringDiffOpKind
enum
#25
Labels
lvl-1-easy
Easy-ranking issue
p2-normal
Priority 2: Someone plans to work on this task in the foreseeable future.
t-code-quality
Improvements to code to make it more maintainable, readable, etc
t-performance
Issue relating to performance, like optimizations or benchmarks
StringDiffOpKind::Delete
holds achar
, but this isn't needed. We only need to know at what position something should be deleted, regardless of what exists at that position.StringDiffOpKind::Transpose
holds twousize
integers but on reflection, doesn't need to hold any (if we're only detecting adjacent transpositions, which means the two letters have to be right next to each other). For example, the Damerau-Levenshtein distance algorithm builds on top of the Levenshtein distance by recognizing transpositions too, but only if they're adjacent.Ultimately, the
StringDiffOpKind
enum should look like:This allows for two nice optimizations:
StringDiffOpKind
was 24 bytes. Now, by reducing unnecessary associated data, it's 8 bytes -> this allows for some memory alignment since it'll take a shorter time to copy on the stack.StringDiffOp
also reduces from 32 bytes to 16 bytes.You can test this by calling
std::mem::size_of()
, with an online Rust playground link to try it out.Some nice resources:
The text was updated successfully, but these errors were encountered: