Skip to content

Conversation

@RicardoTrindade
Copy link
Contributor

@RicardoTrindade RicardoTrindade commented Oct 1, 2024

  • Tiny optimization at the reporting part that is ran at report_supported_gems.
      bundle_gem_specs =
       if ::Bundler.rubygems.respond_to?(:installed_specs)
         ::Bundler.rubygems.installed_specs
       else
         ::Bundler.rubygems.all_specs
       end

If I'm not mistaken the gemspecs in the block above are already being returned sorted alphabetically meaning we can use bsearch instead of find as it will be faster to retrieve the gems.

  • I also understand that in the future this list may not be sorted and reporting might not work as intended so let me know if you disagree with the change
  • Let me know if I should add anything else
  • If possible can this be added to Hacktoberfest ?

@RicardoTrindade
Copy link
Contributor Author

Nevermind, I'm so sorry. I now noticed that the order of the installed gems isn't always guaranteed so I'm closing this one

@tombruijn
Copy link
Member

Hi @RicardoTrindade, thanks for the suggestion!
Would it be worth it to sort the list of gems on our side beforehand and then use bsearch?

@RicardoTrindade
Copy link
Contributor Author

I don't think so but can be wrong of course. From some benchmarks I ran on some other occasion the sorting added some overhead that would cut the benefit of using bsearch making sort(..).find faster.
What I find strange is that if I run Bundler.rubygems.installed_specs.map(&:name) in an irb session then gems come sorted. If I try to print them out during a test run I sometimes see rack and rake being pushed to the top

@tombruijn
Copy link
Member

From some benchmarks I ran on some other occasion the sorting added some overhead that would cut the benefit of using bsearch making sort(..).find faster.

That's too bad.

What I find strange is that if I run Bundler.rubygems.installed_specs.map(&:name) in an irb session then gems come sorted. If I try to print them out during a test run I sometimes see rack and rake being pushed to the top

Based on the output I see from our bundle exec rake console task, the returned order seems to be related to the order in which the gems are defined in our gemspec or an app's Gemfile. That might be where it gets its order. If the Gemfile has an alphabetized order, it probably appears sorted, except for the dependencies.

It's a neat idea for an optimized though! I'm sure there are some other places we can shave off some milliseconds.

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.

2 participants