Skip to content

Instantly share code, notes, and snippets.

@ChrisBr

ChrisBr/foo.md Secret

Last active July 11, 2018 15:50
Show Gist options
  • Save ChrisBr/88ddbe13c382c168071b8acb75790664 to your computer and use it in GitHub Desktop.
Save ChrisBr/88ddbe13c382c168071b8acb75790664 to your computer and use it in GitHub Desktop.

Overview

Idea is to extract different Strategy classes (e.g. OpenAddressStrategy, LinearSearchStrategy) for hash algorithms which we forward to in RubyHash.

Initial approach can be found here: https://github.com/ChrisBr/jruby/commits/performance/hash-extract-class-2

Problems

  • A lot of changes, high probability that something break
  • The Strategy classes are still highly coupled to the RubyHash class as we need to hand over a lot of attributes / variables:
    • flags to calculate the hash value (we could calc the hash in RubyHash and hand it over but then rehashing also needs to happen in RubyHash class?)
    • The methods in the Strategy classes need to be very granular and composed in RubyHash (e.g. check for existence and adding of a RubyString as we need to freeze the string if it doesn't exist (see op_asetForString) or check for iterating (checkIterating))
  • Iterations over key/value pairs need to happen in the Strategy class to be fast, otherwise we need again a temp RubyHashEntry class to use in an iterator (see visitAll)
  • RubyHash needs to know about about DELETED_BIN or EMPTY_BIN values to compose the methods
  • We still need RubyHash to not break API (e.g. getEntry, EntryView)

Benefit

  • Strategy classes are relatively simple to implement
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment