-
-
Notifications
You must be signed in to change notification settings - Fork 39
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Improve Osa implementation #62
Conversation
let b_len = b.chars().count(); | ||
if a == b { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This special case would help performance if the two strings are similar, but hurt if they are not.
Generally it would be better to reduce the common prefix + postfix and return early in case the remaining length is 0. This has the same runtime, but always either helps the performance or doesn't really hurt. In our case the added binary size isn't really worth it though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also guess that it's rare to actually hit these cases in real world usage.
I think we could probably get away with two vectors instead of three. However that's more work and I would need to test the effect of the additional bookkeeping on performance and binary size. For this reason I will try this separately. |
This reduces the binary size of osa_distance by more than 25% while improving the performance.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is awesome! Thanks for the comparison data!
let b_len = b.chars().count(); | ||
if a == b { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would also guess that it's rare to actually hit these cases in real world usage.
This reduces the binary size of osa_distance by more than 25% while improving the performance.
Binary size before change:
Binary size after the change:
The following graph shows the runtime for random strings of different lengths: