Skip to content
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

Merged
merged 4 commits into from
Sep 3, 2015
Merged

Hasher performance #41

merged 4 commits into from
Sep 3, 2015

Conversation

kreynolds
Copy link
Contributor

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.

BEFORE
user     system      total        real
times:    4.400000   0.010000   4.410000 (  4.403278)

AFTER
user     system      total        real
times:    2.630000   0.010000   2.640000 (  2.632828)

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
Copy link
Member

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.

Copy link
Contributor Author

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.

@parkr
Copy link
Member

parkr commented Sep 3, 2015

Woot! Looks good on mobile. Didn't know String#scan worked like that.

@kreynolds
Copy link
Contributor Author

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.

@Ch4s3
Copy link
Member

Ch4s3 commented Sep 3, 2015

@parkr This looks great!

Ch4s3 added a commit that referenced this pull request Sep 3, 2015
@Ch4s3 Ch4s3 merged commit 000f2b7 into jekyll:master Sep 3, 2015
Ch4s3 added a commit that referenced this pull request Sep 3, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants