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

Make IsVendor quicker #44

Merged
merged 1 commit into from Apr 24, 2021
Merged

Make IsVendor quicker #44

merged 1 commit into from Apr 24, 2021

Conversation

zeripath
Copy link
Contributor

Although iterating across the regexps is quicker than naively concatenating them,
it is still quite slow.

This PR proposes a slightly cleverer solution.

First instead of just concatenating with groups this PR uses non-capturing groups.
This speeds up the regexp processing.

Secondly we group the regexps in to 3 groups - those that have to be at the start,
those that are segments or at the start and the rest. This makes a considerable speed
improvement.

Thirdly the regexps are sorted within those groups - which also speeds things up.

All in all for a non-vendored file this makes IsVendor around twice as fast.

Signed-off-by: Andrew Thornton art27@cantab.net

@6543
Copy link
Contributor

6543 commented Apr 1, 2021

I'll add a benchmark test to #45 :)

Copy link
Member

@bzz bzz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @6543! Looks great to me, sans missing high-level doc comment below.

Happy to merge as soon as it is added.

utils.go Show resolved Hide resolved
@bzz bzz added this to the v2.7.0 milestone Apr 22, 2021
@6543
Copy link
Contributor

6543 commented Apr 22, 2021

@zeripath rebase since 45 was merged?

but localy tested it works all fine :)

Although iterating across the regexps is quicker than naively concatenating them,
it is still quite slow.

This PR proposes a slightly cleverer solution.

First instead of just concatenating with groups this PR uses non-capturing groups.
This speeds up the regexp processing.

Secondly we group the regexps in to 3 groups - those that have to be at the start,
those that are segments or at the start and the rest. This makes a considerable speed
improvement.

Thirdly the regexps are sorted within those groups - which also speeds things up.

All in all for a non-vendored file this makes IsVendor around twice as fast.

Signed-off-by: Andrew Thornton <art27@cantab.net>
utils.go Show resolved Hide resolved
@bzz bzz merged commit 7168084 into go-enry:master Apr 24, 2021
@zeripath zeripath deleted the speed-up-is-vendor branch April 26, 2021 18:19
zeripath pushed a commit to go-gitea/gitea that referenced this pull request May 6, 2022
The changes in this file were upstreamed directly into go-enry as go-enry/go-enry#44
and therefore they are no longer needed.
AbdulrhmnGhanem pushed a commit to kitspace/gitea that referenced this pull request Aug 24, 2022
The changes in this file were upstreamed directly into go-enry as go-enry/go-enry#44
and therefore they are no longer needed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants