-
Notifications
You must be signed in to change notification settings - Fork 109
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
Hasher performance #41
Conversation
end | ||
|
||
# Return a word hash without extra punctuation or short symbols, just stemmed words | ||
def clean_word_hash(str, language = 'en') | ||
word_hash_for_words str.gsub(/[^\w\s]/,"").split, language | ||
word_hash_for_words str.gsub(/[^\p{WORD}\s]/,'').downcase.split, language | ||
end |
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.
Why downcase here? Seems like it could have some really problematic side effects.
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.
What side effects? Its not a downcase or gsub in place, it makes a new object which is split, then passed to word_hash_for_words then downcased. All I do is downcase the entire thing at once instead of word*N times.
Woot! Looks good on mobile. Didn't know String#scan worked like that. |
String#scan isn't always faster though .. notice I only changed one of the splits to scan .. benchmarks showed the gsub/split method faster there. |
@parkr This looks great! |
This is a set of simple performance improvements for the Hasher process. Picking a random wikipedia page and hashing it 200 times, I get the following improvements before/after (excluding the Set regression, it was a set before my last PR). Additionally, it fixes broken regex splitting for non-ascii characters and removes the unused punctuation filter.