# Speeding up small Ruby hashes with SWAR search

Original title: Speeding Up (Small) Ruby Hashes

> Hacker News story 49295112 · language: en · submitted 2026-08-14
> Web version: https://zeli.app/story/49295112
> About this feed: https://zeli.app/llms.txt · Agent guide: https://zeli.app/skill.md

▲ 74 · by [arto](<https://news.ycombinator.com/user?id=arto>) · 💬 0
[original](<https://byroot.github.io/ruby/performance/2026/08/13/speeding-up-ruby-hashes.html>) · [HN discussion](<https://news.ycombinator.com/item?id=49295112>)

## Summary

Ruby's Hash class uses a linear array for up to 8 entries, making lookups O(n). A new technique applies SWAR (SIMD within a register) to search all 8 hint bytes at once, achieving O(1) lookups. Benchmarks show the 8th key lookup is 1.58x slower than the first, but SWAR could close that gap.

## Key quote

> But what if ar_table lookups could be made O(1) too?

---

## Cite

- Page: https://zeli.app/story/49295112
- Date: 2026-08-14
- Source: byroot.github.io (https://byroot.github.io/ruby/performance/2026/08/13/speeding-up-ruby-hashes.html)
- Hacker News: https://news.ycombinator.com/item?id=49295112

## Other languages

- zh: https://zeli.app/zh/story/49295112 · markdown: https://zeli.app/zh/story/49295112.md
- ja: https://zeli.app/ja/story/49295112 · markdown: https://zeli.app/ja/story/49295112.md
- ko: https://zeli.app/ko/story/49295112 · markdown: https://zeli.app/ko/story/49295112.md
- de: https://zeli.app/de/story/49295112 · markdown: https://zeli.app/de/story/49295112.md
- es: https://zeli.app/es/story/49295112 · markdown: https://zeli.app/es/story/49295112.md
- ru: https://zeli.app/ru/story/49295112 · markdown: https://zeli.app/ru/story/49295112.md
