Skip to content

Conversation

@austinpray
Copy link
Contributor

@austinpray austinpray commented Jul 26, 2020


Description:

replaces Bundler::SimilarityDetector with DidYouMean::SpellChecker

  1. Higher quality spelling suggestions in my testing
  2. Benefit from upstream improvements, less code to maintain in this repo. The current Bundler::SimilarityDetector.levenshtein_distance dynamic programming implementation could be optimized quite a bit.
  3. Should see a significant performance improvement, under the hood DidYouMean::SpellChecker is highly optimized.

RubyGems 3.0 supports Ruby 2.3 or later. Ruby 2.3 and later ships with the did_you_mean gem.

https://stdgems.org/did_you_mean/

Higher quality spelling suggestions

The algorithm seems to

Tested with the rails 6 gemfile. Here's some results from manually stressing the spell checker:

input old new
regexparser (none) Did you mean 'regexp_parser'?
miniportile (none) Did you mean 'mini_portile2'?
rails-sanitizer-html (none) Did you mean 'rails-html-sanitizer'?
sqilte3 Did you mean sqlite3? Did you mean 'sqlite3'?
sqte3 (none) Did you mean 'sqlite3'?

Benchmark

💹 Benchmark code (permalink)

This looks like a 7x performance boost. The DidYouMean implementation also uses less memory and such.

Warming up --------------------------------------
              Before    12.000  i/100ms
               After    94.000  i/100ms
Calculating -------------------------------------
              Before    124.193  (± 1.6%) i/s -    624.000  in   5.025368s
               After    937.282  (± 0.9%) i/s -      4.700k in   5.014849s

Notes for reviewer

  • Bundler::SimilarityDetector is not used in Bundler anymore. I would like to delete it, but I haven't haven't because I am not sure if we should pull the rug out from people that might be using for their own purposes. What should we do to phase out this module?

What was the end-user or developer problem that led to this PR?

Was improving performance over in #3856 and saw this as an opportunity as well.

What is your fix for the problem, implemented in this PR?

Use DidYouMean::SpellChecker as a drop-in replacement for Bundler::SimilarityDetector


Tasks:

  • Describe the problem / feature
  • Write tests
  • Write code to solve the problem
  • Get code review from coworkers / friends

I will abide by the code of conduct.

return words[0]
end

[words[0..-2].join(", "), words[-1]].join(" or ")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Suggested change
[words[0..-2].join(", "), words[-1]].join(" or ")
[words[0..-2].join(", "), words[-1]].join(", or ")

Personally I like oxford commas ("apple, orange, or pear"). I went without it so the output is similar to how it has always been ("apple, orange or pear").

# frozen_string_literal: true

# This module is not used anywhere in Bundler
# It is included for backwards compatibility in-case someone is relying on it
Copy link
Contributor Author

Choose a reason for hiding this comment

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

I left this module in here so I don't pull the rug out from someone who might be using it in their own project. I would like to delete it, is there a deprecation path for stuff like this?

Copy link
Contributor Author

@austinpray austinpray left a comment

Choose a reason for hiding this comment

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

Same concern as #3856 (review)

@austinpray austinpray marked this pull request as draft July 31, 2020 20:02
@austinpray austinpray marked this pull request as ready for review August 2, 2020 01:53
@hsbt hsbt force-pushed the levenshtein-dym-bundler branch from c2d83ae to aaaedc8 Compare March 10, 2023 09:19
@hsbt
Copy link
Member

hsbt commented Mar 10, 2023

@austinpray Can you update this Pr by rubocop -a bundler/lib/bundler/cli/common.rb?

@hsbt hsbt force-pushed the levenshtein-dym-bundler branch from aaaedc8 to 990970f Compare August 8, 2023 04:50
@hsbt hsbt force-pushed the levenshtein-dym-bundler branch from 9a5c3d1 to 6a67d88 Compare November 18, 2025 06:39
@hsbt hsbt force-pushed the levenshtein-dym-bundler branch from 6a67d88 to d604c1d Compare November 18, 2025 07:44
@hsbt hsbt enabled auto-merge November 18, 2025 08:06
https://github.com/ruby/rubygems/actions/runs/19458155903/job/55676075439?pr=3857

```
       -Did you mean 'methods' or 'method'?
       +Could not find gem 'methosd'.
       +Did you mean 'method' or 'methods'?
```
@hsbt hsbt merged commit 9711b0c into ruby:master Nov 18, 2025
76 checks passed
@hsbt
Copy link
Member

hsbt commented Nov 18, 2025

@austinpray Sorry to my late action. I'm happy to introduce this feature at Bundler 4 and Ruby 4.0. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants