zxcvbn-rb icon indicating copy to clipboard operation
zxcvbn-rb copied to clipboard

Lazy loaded (and evictable) dictionaries clobbers test suite performance

Open hyodyllinentekniikka opened this issue 1 year ago • 1 comments

After upgrading to 1.0.0 our rspec test suite completion time has increased from ~4m20s to ~6m30s.

We expect this is due to lazy loading the dictionaries. Is there a way to eager load them for the test suite?

hyodyllinentekniikka avatar Apr 26 '25 06:04 hyodyllinentekniikka

Hello @hyodyllinentekniikka ,

I had the same issue initially, this was expected, though, as dictionaries now can be removed from memory after use. You could keep the dictionaries in memory using the strategy delineated at https://github.com/formigarafa/zxcvbn-rb?tab=readme-ov-file#testing-multiple-passwords.

To just get the old behaviour you can just replace the usages of zxcvbn with that strategy.

To get a different behaviour on test mode only you may need to implement some sort of test mode to keep the dictionaries loaded in memory.

A quick way to do it would be to have this piece of code loaded before your tests run:

module Zxcvbn
  def self.tester
    @tester ||= Zxcvbn::Tester.new
  end

  def self.zxcvbn(*)
    tester.zxcvbn(*)
  end

  def self.test(password, user_inputs = [])
    tester.test(password, user_inputs)
  end
end

formigarafa avatar Apr 30 '25 22:04 formigarafa