- Notifications
You must be signed in to change notification settings - Fork6
Fast & memory efficient hash tables for Java
License
NotificationsYou must be signed in to change notification settings
bluuewhale/hash-smith
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
- HashSmith provides multiple high-performance hash table implementations optimized for speed and memory efficiency on modern JVMs.
- Focus areas: SWAR-probing (
SwissMap), SIMD-probing (SwissSimdMap), predictable probe lengths (Robin Hood), and minimal per-entry overhead. - Built for JDK 21+;
SwissSimdMapuses the incubating Vector API for SIMD acceleration. - More memory-efficient than the built-in JDK
HashMap; performance depends on workload.
- SwissMap: SwissTable-inspired design using SWAR control-byte probing (no Vector API) with tombstone reuse. Default map.
- SwissSimdMap: SIMD (Vector API incubator) variant of SwissMap with vectorized control-byte probing. See
docs/SwissSimdMap.mdfor details. - ConcurrentSwissMap: sharded, thread-safe wrapper around
SwissMapusing per-shardStampedLock(null keys not supported). - SwissSet: SwissTable-style hash set with SIMD control-byte probing, tombstone reuse, and null-element support
Vector API is still incubating, and profiling on my setup showed the SIMD path taking longer than expected, so the defaultSwissMap favors a SWAR probe. Numbers can differ significantly by hardware/JVM version; please run your own benchmarks if you plan to useSwissSimdMap.
- If you want a guided tour with design notes and benchmarks, seethis write-up.
import io.github.bluuewhale.hashsmith.SwissMap; // SWARimport io.github.bluuewhale.hashsmith.ConcurrentSwissMap;import io.github.bluuewhale.hashsmith.SwissSet;// SwissMap (SWAR)var swiss = new SwissMap<String, Integer>();swiss.put("a", 1);swiss.get("a"); // 1// ConcurrentSwissMap (sharded, thread-safe)var concurrentSwiss = new ConcurrentSwissMap<String, Integer>();concurrentSwiss.put("a", 1);concurrentSwiss.get("a"); // 1// SwissSetvar swissSet = new SwissSet<String>();swissSet.add("k");swissSet.add(null); // nulls allowedswissSet.contains("k"); // true- Gradle (Kotlin DSL):
dependencies { implementation("io.github.bluuewhale:hashsmith:0.1.8")}- Gradle (Groovy):
dependencies { implementation 'io.github.bluuewhale:hashsmith:0.1.8'}- Maven:
<dependency> <groupId>io.github.bluuewhale</groupId> <artifactId>hashsmith</artifactId> <version>0.1.8</version></dependency>- JDK 21+ (
SwissSimdMapneedsjdk.incubator.vector) - Gradle (wrapper provided)
- The JVM flag
--add-modules jdk.incubator.vectoris already configured for build, test, and JMH tasks that exerciseSwissSimdMap.
./gradlew build # full build./gradlew test # JUnit 5 tests- Compares retained heap for both maps (
HashMapvsSwissSimdMapvsSwissMapvs fastutilObject2ObjectOpenHashMapvs Eclipse CollectionsUnifiedMap) and sets (HashSetvsSwissSetvs fastutilObjectOpenHashSetvs Eclipse CollectionsUnifiedSet). - Set benchmarks use UUID
Stringkeys (HashSet, SwissSet, ObjectOpenHashSet, UnifiedSet). Primitive-specialized collections (e.g., fastutil primitive sets) are excluded because their memory profile is driven by primitive storage, whereas these tests target general reference workloads.
- Maps:
SwissMap/SwissSimdMapuse open addressing to cut space; default load factor 0.875, up to 53.3% retained-heap reduction in payload-light cases vsHashMap. - Sets:
SwissSet(SwissHashSet) mirrors the SwissTable layout with SIMD control-byte probing and reuses tombstones to stay denser thanHashSetacross tested payloads, showing up to ~62% retained-heap reduction in lighter payload cases.
| Map | Set |
|---|---|
![]() | ![]() |
- All benchmarks were run on Windows 11 (x64) with Eclipse Temurin JDK 21.0.9, on an AMD Ryzen 5 5600 (6C/12T).
- At high load factors SwissMap (SWAR) stay competitive against other open-addressing tables and close to JDK HashMap performance; depending on hardware/JVM, one may edge out the other.
| put hit | put miss |
|---|---|
![]() | ![]() |
| get hit | get miss |
|---|---|
![]() | ![]() |
- Open an issue for bugs/ideas
- Work on a feature branch and open a PR
- Keep tests/JMH green before submitting
- This project is licensed under the MIT License. See
LICENSEfor details.
About
Fast & memory efficient hash tables for Java
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Contributors3
Uh oh!
There was an error while loading.Please reload this page.






