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

Refactor PathScanner to avoid Dir.glob #312

Merged
merged 1 commit into from Jun 29, 2020
Merged

Conversation

casperisfine
Copy link
Contributor

My main concern with Dir.glob is that it becomes sorted by default in 2.8/3.0 which makes it quite slower for large result sets. That can easily be fixed by passing sort: false, but while I was at it I figured there might be ways to avoid the cost of allocating and returning giant arrays.

So instead I use foreach which yield directory entries one by one.

I benched it against large directories and it's noticeably faster: https://gist.github.com/casperisfine/68819290350f8036d48a1d71777d5616

Calculating -------------------------------------
            original     18.595  (± 5.4%) i/s -    372.000  in  20.025736s
                 new     25.369  (± 3.9%) i/s -    508.000  in  20.037516s

Comparison:
                 new:       25.4 i/s
            original:       18.6 i/s - 1.36x  (± 0.00) slower

@casperisfine casperisfine requested a review from burke as a code owner June 28, 2020 22:33
@casperisfine casperisfine merged commit 56c6137 into master Jun 29, 2020
@casperisfine casperisfine deleted the path-scanner-refactor branch June 29, 2020 17:23
@XrXr XrXr temporarily deployed to rubygems October 24, 2020 22:20 Inactive
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.

None yet

4 participants