Skip to content

Hashery 2.2.0: faster LRUHash, bug fixes, modernized project - #27

Merged
trans merged 9 commits into
masterfrom
modernize-2.2
Nov 16, 2026
Merged

trans merged 9 commits into
masterfrom
modernize-2.2

Conversation

@trans

@trans trans commented Nov 16, 2026

Copy link
Copy Markdown
Member

Almost all of hashery's downloads come from pdf-reader, which loads hashery/lru_hash and pins hashery ~> 2.0. So this release concentrates on LRUHash and keeps it fully compatible: a 2.2.0 reaches every pdf-reader user automatically.

LRUHash

  • Faster: entries now live in Ruby's own ordered Hash instead of a linked list of Struct nodes. It is about 2x faster on Ruby 2.7, 3.4 and 4.0 (1.5–2.5x with YJIT).
  • Same public API and behavior: I ran 900k random operations against the 2.1.2 implementation and the new one. Return values, iteration order, evictions and every release_proc call matched. A planted bug was caught, so the check works.
  • Fixed:
    • dup and clone shared internal state with the original, so writing to a copy corrupted it.
    • inspect and to_s printed keys and values with to_s ({=>1, a=>x}) and fail when frozen string literals are enabled.
  • Hash-like additions: fetch(key, default), a KeyError that names the key, delete(key) { ... }, delete_if without a block returns an Enumerator, and length.
  • Visible change: keys and values now list most recently used first, matching each. Before, they came out roughly in insertion order.

Other fixes

  • IniHash.new(hash) raised a TypeError, which broke IniHash.text and IniHash.write_to_file. write_to_file with a comment also called String#each, gone since Ruby 1.9.
  • require 'hashery/static_hash' failed when loaded on its own.
  • No warnings under ruby -w, and no mutation of string literals.

Project

  • A plain hashery.gemspec replaces the Indexer metadata (.gemspec, .index, Index.yml, Assembly, MANIFEST, lib/hashery.yml). It requires Ruby 2.7 or newer and gets its version from lib/hashery/version.rb, now 2.2.0. The built gem ships the same files and require_paths as 2.1.2, minus the Indexer metadata.
  • GitHub Actions replaces Travis CI. It runs the Lemon unit tests and QED demos on Ruby 2.7 through 4.0, plus the demos with frozen string literals on 4.0.
  • README: an LRUHash section, https links, the github.io homepage (fixes Fix about link #26), and dead Travis, Gittip and freenode links removed. HISTORY has a 2.2.0 entry.

Testing

  • Unit tests and demos: 223 Lemon tests and 68 QED steps pass on Ruby 2.7.8, 3.4.9 and 4.0.9. Every commit in this PR passes on its own.
  • Gem install: the gem built from hashery.gemspec installs and loads on 2.7 and 4.0.
  • pdf-reader: its full suite (d7a9ec6, Ruby 3.4.9) gives 2274 examples, 0 failures, 6 pending against both 2.1.2 and this branch, with the same 6 pending.
    • At its default cache size of 1000, pdf-reader's specs never evict. So I also ran both versions with ObjectCache forced down to 2 entries: the results were identical, with matching read, write and key-check counts.

Saved for a 3.0

These would change behavior, so they're left out here: has_value? comparing with == like Hash, LRUHash#== and #to_hash, and sensible behavior for a frozen LRUHash.

🤖 Generated with Claude Code

trans and others added 9 commits November 9, 2026 00:35
Parenthesize ambiguous splat and block arguments, fix a mismatched
indentation and drop an unused variable.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Build strings from unfrozen buffers so FuzzyHash and IniHash keep
working when string literals are frozen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
StaticHash subclasses CRUDHash but never required it, so loading
hashery/static_hash by itself raised NameError.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
IniHash.new(hash) passed a nil path to FileTest.readable_real? and
raised TypeError, which also broke IniHash.text and write_to_file.
write_to_file with a comment called String#each, gone since Ruby 1.9.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Keep entries in a plain Hash ordered from least to most recently used,
promoting an entry by deleting and re-inserting it, instead of a linked
list of Struct nodes. This is about twice as fast on Ruby 2.7 through
4.0. The public API is unchanged, and randomized differential tests
against the 2.1.2 implementation show identical results, iteration
order, evictions and release_proc calls.

Also fixes and Hash-compatible additions:

* dup and clone no longer share state with the original.
* inspect and to_s show keys and values like Hash#inspect, and no
  longer mutate a string literal.
* keys and values list most recently used first, matching each.
* fetch accepts a default argument; its KeyError names the key.
* delete takes a block for missing keys.
* delete_if returns an Enumerator without a block.
* Add length.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The Indexer exporter could not set required_ruby_version. Use a plain
gemspec instead, now requiring Ruby 2.7 or newer, with the version in
lib/hashery/version.rb (bumped to 2.2.0; Hashery::VERSION still said
2.1.0). The gem keeps the same files and require_paths as 2.1.2, minus
the Indexer metadata. The Gemfile now uses the gemspec, and the Rakefile
gains bundler's gem tasks and a default task.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Run the unit tests and demos on Ruby 2.7 through 4.0, plus the demos
with frozen string literals enabled on 4.0.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Add an LRUHash section, note the Ruby 2.7 requirement, describe running
the tests with Bundler, use https and the github.io homepage, and drop
the dead Travis, Gittip and freenode links.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@trans
trans merged commit 9c7e656 into master Nov 16, 2026
14 checks passed
@trans
trans deleted the modernize-2.2 branch November 17, 2026 13:37
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.

Fix about link

1 participant