├── .github └── workflows │ ├── release.yml │ └── rust.yml ├── .gitignore ├── .release-please-manifest.json ├── CHANGELOG.md ├── Cargo.lock ├── Cargo.toml ├── LICENSE ├── README.md ├── results ├── Exchange.ahash.csv ├── Exchange.ahash.latency.svg ├── Exchange.ahash.throughput.svg ├── Exchange.std.csv ├── Exchange.std.latency.svg ├── Exchange.std.throughput.svg ├── RapidGrow.ahash.csv ├── RapidGrow.ahash.latency.svg ├── RapidGrow.ahash.throughput.svg ├── RapidGrow.std.csv ├── RapidGrow.std.latency.svg ├── RapidGrow.std.throughput.svg ├── ReadHeavy.ahash.csv ├── ReadHeavy.ahash.latency.svg ├── ReadHeavy.ahash.throughput.svg ├── ReadHeavy.std.csv ├── ReadHeavy.std.latency.svg └── ReadHeavy.std.throughput.svg ├── src ├── lib.rs ├── mapref.rs ├── shard.rs ├── shard_map.rs └── shard_set.rs └── tests └── basic.rs /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: 9 | contents: write 10 | pull-requests: write 11 | 12 | jobs: 13 | release-please: 14 | 15 | runs-on: ubuntu-latest 16 | 17 | steps: 18 | - uses: googleapis/release-please-action@v4 19 | id: release 20 | with: 21 | token: ${{ secrets.GH_DEPLOY_TOKEN }} 22 | release-type: rust 23 | 24 | - uses: actions/checkout@v4 25 | if: ${{ steps.release.outputs.release_created }} 26 | 27 | - uses: dtolnay/rust-toolchain@stable 28 | if: ${{ steps.release.outputs.release_created }} 29 | 30 | - run: cargo login ${{ secrets.CARGO_PUBLISH_TOKEN }} 31 | if: ${{ steps.release.outputs.release_created }} 32 | 33 | - run: cargo publish 34 | if: ${{ steps.release.outputs.release_created }} 35 | -------------------------------------------------------------------------------- /.github/workflows/rust.yml: -------------------------------------------------------------------------------- 1 | name: Rust 2 | 3 | on: 4 | push: 5 | branches: [ "main" ] 6 | paths: 7 | - src/ 8 | - tests/ 9 | - Cargo.toml 10 | - Cargo.lock 11 | - .github/ 12 | 13 | pull_request: 14 | branches: [ "main" ] 15 | paths: 16 | - src/ 17 | - tests/ 18 | - Cargo.toml 19 | - Cargo.lock 20 | - .github/ 21 | 22 | env: 23 | CARGO_TERM_COLOR: always 24 | 25 | jobs: 26 | tests: 27 | name: "Run tests" 28 | 29 | runs-on: ubuntu-latest 30 | 31 | steps: 32 | - uses: actions/checkout@v4 33 | - name: Build 34 | run: cargo build --verbose 35 | - name: Run tests 36 | run: cargo test --verbose 37 | 38 | miri: 39 | name: "Miri" 40 | runs-on: ubuntu-latest 41 | steps: 42 | - uses: actions/checkout@v4 43 | - name: Install Miri 44 | run: | 45 | rustup toolchain install nightly --component miri 46 | rustup override set nightly 47 | cargo miri setup 48 | - name: Test with Miri 49 | run: cargo miri test 50 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | /target 2 | -------------------------------------------------------------------------------- /.release-please-manifest.json: -------------------------------------------------------------------------------- 1 | { 2 | ".": "0.1.1" 3 | } 4 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | # Changelog 2 | 3 | ## [0.1.1](https://github.com/fortress-build/whirlwind/compare/v0.1.0...v0.1.1) (2024-11-04) 4 | 5 | 6 | ### Miscellaneous Chores 7 | 8 | * update minor version ([f36a463](https://github.com/fortress-build/whirlwind/commit/f36a463c0b6b7886282fbe68d45e76edace1beae)) 9 | 10 | ## [0.1.0](https://github.com/fortress-build/whirlwind/compare/v0.1.0-rc1...v0.1.0) (2024-11-03) 11 | 12 | 13 | ### Features 14 | 15 | * allow custom hasher implementations ([0dbc985](https://github.com/fortress-build/whirlwind/commit/0dbc9857825786e7bf2dfc8b4364cddd331b5bc4)) 16 | 17 | 18 | ### Bug Fixes 19 | 20 | * add `crossbeam_utils` dependency ([f9ad383](https://github.com/fortress-build/whirlwind/commit/f9ad38370be37543dd3af81bc217658094a93b7a)) 21 | * versioning for release-please ([1d51202](https://github.com/fortress-build/whirlwind/commit/1d51202687c710c8fc441bb3cb9d201530956250)) 22 | 23 | 24 | ### Performance Improvements 25 | 26 | * use `hashbrown::HashTable` for shards ([f0d45f1](https://github.com/fortress-build/whirlwind/commit/f0d45f1d4b110b6b8c36439e375b4f7c685e4a8e)) 27 | * use `hashbrown::RawTable` + `dashmap`'s shard selection strategy ([c47f3ef](https://github.com/fortress-build/whirlwind/commit/c47f3efb0715ace74e75ecdeee840298d4da34db)) 28 | -------------------------------------------------------------------------------- /Cargo.lock: -------------------------------------------------------------------------------- 1 | # This file is automatically @generated by Cargo. 2 | # It is not intended for manual editing. 3 | version = 4 4 | 5 | [[package]] 6 | name = "addr2line" 7 | version = "0.24.2" 8 | source = "registry+https://github.com/rust-lang/crates.io-index" 9 | checksum = "dfbe277e56a376000877090da837660b4427aad530e3028d44e0bffe4f89a1c1" 10 | dependencies = [ 11 | "gimli", 12 | ] 13 | 14 | [[package]] 15 | name = "adler2" 16 | version = "2.0.0" 17 | source = "registry+https://github.com/rust-lang/crates.io-index" 18 | checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627" 19 | 20 | [[package]] 21 | name = "allocator-api2" 22 | version = "0.2.18" 23 | source = "registry+https://github.com/rust-lang/crates.io-index" 24 | checksum = "5c6cb57a04249c6480766f7f7cef5467412af1490f8d1e243141daddada3264f" 25 | 26 | [[package]] 27 | name = "autocfg" 28 | version = "1.4.0" 29 | source = "registry+https://github.com/rust-lang/crates.io-index" 30 | checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26" 31 | 32 | [[package]] 33 | name = "backtrace" 34 | version = "0.3.74" 35 | source = "registry+https://github.com/rust-lang/crates.io-index" 36 | checksum = "8d82cb332cdfaed17ae235a638438ac4d4839913cc2af585c3c6746e8f8bee1a" 37 | dependencies = [ 38 | "addr2line", 39 | "cfg-if", 40 | "libc", 41 | "miniz_oxide", 42 | "object", 43 | "rustc-demangle", 44 | "windows-targets", 45 | ] 46 | 47 | [[package]] 48 | name = "bitflags" 49 | version = "2.6.0" 50 | source = "registry+https://github.com/rust-lang/crates.io-index" 51 | checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de" 52 | 53 | [[package]] 54 | name = "bytes" 55 | version = "1.8.0" 56 | source = "registry+https://github.com/rust-lang/crates.io-index" 57 | checksum = "9ac0150caa2ae65ca5bd83f25c7de183dea78d4d366469f148435e2acfbad0da" 58 | 59 | [[package]] 60 | name = "cfg-if" 61 | version = "1.0.0" 62 | source = "registry+https://github.com/rust-lang/crates.io-index" 63 | checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd" 64 | 65 | [[package]] 66 | name = "crossbeam-utils" 67 | version = "0.8.20" 68 | source = "registry+https://github.com/rust-lang/crates.io-index" 69 | checksum = "22ec99545bb0ed0ea7bb9b8e1e9122ea386ff8a48c0922e43f36d45ab09e0e80" 70 | 71 | [[package]] 72 | name = "equivalent" 73 | version = "1.0.1" 74 | source = "registry+https://github.com/rust-lang/crates.io-index" 75 | checksum = "5443807d6dff69373d433ab9ef5378ad8df50ca6298caf15de6e52e24aaf54d5" 76 | 77 | [[package]] 78 | name = "foldhash" 79 | version = "0.1.3" 80 | source = "registry+https://github.com/rust-lang/crates.io-index" 81 | checksum = "f81ec6369c545a7d40e4589b5597581fa1c441fe1cce96dd1de43159910a36a2" 82 | 83 | [[package]] 84 | name = "gimli" 85 | version = "0.31.1" 86 | source = "registry+https://github.com/rust-lang/crates.io-index" 87 | checksum = "07e28edb80900c19c28f1072f2e8aeca7fa06b23cd4169cefe1af5aa3260783f" 88 | 89 | [[package]] 90 | name = "hashbrown" 91 | version = "0.15.1" 92 | source = "registry+https://github.com/rust-lang/crates.io-index" 93 | checksum = "3a9bfc1af68b1726ea47d3d5109de126281def866b33970e10fbab11b5dafab3" 94 | dependencies = [ 95 | "allocator-api2", 96 | "equivalent", 97 | "foldhash", 98 | ] 99 | 100 | [[package]] 101 | name = "hermit-abi" 102 | version = "0.3.9" 103 | source = "registry+https://github.com/rust-lang/crates.io-index" 104 | checksum = "d231dfb89cfffdbc30e7fc41579ed6066ad03abda9e567ccafae602b97ec5024" 105 | 106 | [[package]] 107 | name = "libc" 108 | version = "0.2.161" 109 | source = "registry+https://github.com/rust-lang/crates.io-index" 110 | checksum = "8e9489c2807c139ffd9c1794f4af0ebe86a828db53ecdc7fea2111d0fed085d1" 111 | 112 | [[package]] 113 | name = "lock_api" 114 | version = "0.4.12" 115 | source = "registry+https://github.com/rust-lang/crates.io-index" 116 | checksum = "07af8b9cdd281b7915f413fa73f29ebd5d55d0d3f0155584dade1ff18cea1b17" 117 | dependencies = [ 118 | "autocfg", 119 | "scopeguard", 120 | ] 121 | 122 | [[package]] 123 | name = "memchr" 124 | version = "2.7.4" 125 | source = "registry+https://github.com/rust-lang/crates.io-index" 126 | checksum = "78ca9ab1a0babb1e7d5695e3530886289c18cf2f87ec19a575a0abdce112e3a3" 127 | 128 | [[package]] 129 | name = "miniz_oxide" 130 | version = "0.8.0" 131 | source = "registry+https://github.com/rust-lang/crates.io-index" 132 | checksum = "e2d80299ef12ff69b16a84bb182e3b9df68b5a91574d3d4fa6e41b65deec4df1" 133 | dependencies = [ 134 | "adler2", 135 | ] 136 | 137 | [[package]] 138 | name = "mio" 139 | version = "1.0.2" 140 | source = "registry+https://github.com/rust-lang/crates.io-index" 141 | checksum = "80e04d1dcff3aae0704555fe5fee3bcfaf3d1fdf8a7e521d5b9d2b42acb52cec" 142 | dependencies = [ 143 | "hermit-abi", 144 | "libc", 145 | "wasi", 146 | "windows-sys", 147 | ] 148 | 149 | [[package]] 150 | name = "object" 151 | version = "0.36.5" 152 | source = "registry+https://github.com/rust-lang/crates.io-index" 153 | checksum = "aedf0a2d09c573ed1d8d85b30c119153926a2b36dce0ab28322c09a117a4683e" 154 | dependencies = [ 155 | "memchr", 156 | ] 157 | 158 | [[package]] 159 | name = "parking_lot" 160 | version = "0.12.3" 161 | source = "registry+https://github.com/rust-lang/crates.io-index" 162 | checksum = "f1bf18183cf54e8d6059647fc3063646a1801cf30896933ec2311622cc4b9a27" 163 | dependencies = [ 164 | "lock_api", 165 | "parking_lot_core", 166 | ] 167 | 168 | [[package]] 169 | name = "parking_lot_core" 170 | version = "0.9.10" 171 | source = "registry+https://github.com/rust-lang/crates.io-index" 172 | checksum = "1e401f977ab385c9e4e3ab30627d6f26d00e2c73eef317493c4ec6d468726cf8" 173 | dependencies = [ 174 | "cfg-if", 175 | "libc", 176 | "redox_syscall", 177 | "smallvec", 178 | "windows-targets", 179 | ] 180 | 181 | [[package]] 182 | name = "pin-project-lite" 183 | version = "0.2.15" 184 | source = "registry+https://github.com/rust-lang/crates.io-index" 185 | checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff" 186 | 187 | [[package]] 188 | name = "proc-macro2" 189 | version = "1.0.89" 190 | source = "registry+https://github.com/rust-lang/crates.io-index" 191 | checksum = "f139b0662de085916d1fb67d2b4169d1addddda1919e696f3252b740b629986e" 192 | dependencies = [ 193 | "unicode-ident", 194 | ] 195 | 196 | [[package]] 197 | name = "quote" 198 | version = "1.0.37" 199 | source = "registry+https://github.com/rust-lang/crates.io-index" 200 | checksum = "b5b9d34b8991d19d98081b46eacdd8eb58c6f2b201139f7c5f643cc155a633af" 201 | dependencies = [ 202 | "proc-macro2", 203 | ] 204 | 205 | [[package]] 206 | name = "redox_syscall" 207 | version = "0.5.7" 208 | source = "registry+https://github.com/rust-lang/crates.io-index" 209 | checksum = "9b6dfecf2c74bce2466cabf93f6664d6998a69eb21e39f4207930065b27b771f" 210 | dependencies = [ 211 | "bitflags", 212 | ] 213 | 214 | [[package]] 215 | name = "rustc-demangle" 216 | version = "0.1.24" 217 | source = "registry+https://github.com/rust-lang/crates.io-index" 218 | checksum = "719b953e2095829ee67db738b3bfa9fa368c94900df327b3f07fe6e794d2fe1f" 219 | 220 | [[package]] 221 | name = "scopeguard" 222 | version = "1.2.0" 223 | source = "registry+https://github.com/rust-lang/crates.io-index" 224 | checksum = "94143f37725109f92c262ed2cf5e59bce7498c01bcc1502d7b9afe439a4e9f49" 225 | 226 | [[package]] 227 | name = "signal-hook-registry" 228 | version = "1.4.2" 229 | source = "registry+https://github.com/rust-lang/crates.io-index" 230 | checksum = "a9e9e0b4211b72e7b8b6e85c807d36c212bdb33ea8587f7569562a84df5465b1" 231 | dependencies = [ 232 | "libc", 233 | ] 234 | 235 | [[package]] 236 | name = "smallvec" 237 | version = "1.13.2" 238 | source = "registry+https://github.com/rust-lang/crates.io-index" 239 | checksum = "3c5e1a9a646d36c3599cd173a41282daf47c44583ad367b8e6837255952e5c67" 240 | 241 | [[package]] 242 | name = "socket2" 243 | version = "0.5.7" 244 | source = "registry+https://github.com/rust-lang/crates.io-index" 245 | checksum = "ce305eb0b4296696835b71df73eb912e0f1ffd2556a501fcede6e0c50349191c" 246 | dependencies = [ 247 | "libc", 248 | "windows-sys", 249 | ] 250 | 251 | [[package]] 252 | name = "syn" 253 | version = "2.0.85" 254 | source = "registry+https://github.com/rust-lang/crates.io-index" 255 | checksum = "5023162dfcd14ef8f32034d8bcd4cc5ddc61ef7a247c024a33e24e1f24d21b56" 256 | dependencies = [ 257 | "proc-macro2", 258 | "quote", 259 | "unicode-ident", 260 | ] 261 | 262 | [[package]] 263 | name = "tokio" 264 | version = "1.41.0" 265 | source = "registry+https://github.com/rust-lang/crates.io-index" 266 | checksum = "145f3413504347a2be84393cc8a7d2fb4d863b375909ea59f2158261aa258bbb" 267 | dependencies = [ 268 | "backtrace", 269 | "bytes", 270 | "libc", 271 | "mio", 272 | "parking_lot", 273 | "pin-project-lite", 274 | "signal-hook-registry", 275 | "socket2", 276 | "tokio-macros", 277 | "windows-sys", 278 | ] 279 | 280 | [[package]] 281 | name = "tokio-macros" 282 | version = "2.4.0" 283 | source = "registry+https://github.com/rust-lang/crates.io-index" 284 | checksum = "693d596312e88961bc67d7f1f97af8a70227d9f90c31bba5806eec004978d752" 285 | dependencies = [ 286 | "proc-macro2", 287 | "quote", 288 | "syn", 289 | ] 290 | 291 | [[package]] 292 | name = "unicode-ident" 293 | version = "1.0.13" 294 | source = "registry+https://github.com/rust-lang/crates.io-index" 295 | checksum = "e91b56cd4cadaeb79bbf1a5645f6b4f8dc5bde8834ad5894a8db35fda9efa1fe" 296 | 297 | [[package]] 298 | name = "wasi" 299 | version = "0.11.0+wasi-snapshot-preview1" 300 | source = "registry+https://github.com/rust-lang/crates.io-index" 301 | checksum = "9c8d87e72b64a3b4db28d11ce29237c246188f4f51057d65a7eab63b7987e423" 302 | 303 | [[package]] 304 | name = "whirlwind" 305 | version = "0.1.1" 306 | dependencies = [ 307 | "crossbeam-utils", 308 | "hashbrown", 309 | "tokio", 310 | ] 311 | 312 | [[package]] 313 | name = "windows-sys" 314 | version = "0.52.0" 315 | source = "registry+https://github.com/rust-lang/crates.io-index" 316 | checksum = "282be5f36a8ce781fad8c8ae18fa3f9beff57ec1b52cb3de0789201425d9a33d" 317 | dependencies = [ 318 | "windows-targets", 319 | ] 320 | 321 | [[package]] 322 | name = "windows-targets" 323 | version = "0.52.6" 324 | source = "registry+https://github.com/rust-lang/crates.io-index" 325 | checksum = "9b724f72796e036ab90c1021d4780d4d3d648aca59e491e6b98e725b84e99973" 326 | dependencies = [ 327 | "windows_aarch64_gnullvm", 328 | "windows_aarch64_msvc", 329 | "windows_i686_gnu", 330 | "windows_i686_gnullvm", 331 | "windows_i686_msvc", 332 | "windows_x86_64_gnu", 333 | "windows_x86_64_gnullvm", 334 | "windows_x86_64_msvc", 335 | ] 336 | 337 | [[package]] 338 | name = "windows_aarch64_gnullvm" 339 | version = "0.52.6" 340 | source = "registry+https://github.com/rust-lang/crates.io-index" 341 | checksum = "32a4622180e7a0ec044bb555404c800bc9fd9ec262ec147edd5989ccd0c02cd3" 342 | 343 | [[package]] 344 | name = "windows_aarch64_msvc" 345 | version = "0.52.6" 346 | source = "registry+https://github.com/rust-lang/crates.io-index" 347 | checksum = "09ec2a7bb152e2252b53fa7803150007879548bc709c039df7627cabbd05d469" 348 | 349 | [[package]] 350 | name = "windows_i686_gnu" 351 | version = "0.52.6" 352 | source = "registry+https://github.com/rust-lang/crates.io-index" 353 | checksum = "8e9b5ad5ab802e97eb8e295ac6720e509ee4c243f69d781394014ebfe8bbfa0b" 354 | 355 | [[package]] 356 | name = "windows_i686_gnullvm" 357 | version = "0.52.6" 358 | source = "registry+https://github.com/rust-lang/crates.io-index" 359 | checksum = "0eee52d38c090b3caa76c563b86c3a4bd71ef1a819287c19d586d7334ae8ed66" 360 | 361 | [[package]] 362 | name = "windows_i686_msvc" 363 | version = "0.52.6" 364 | source = "registry+https://github.com/rust-lang/crates.io-index" 365 | checksum = "240948bc05c5e7c6dabba28bf89d89ffce3e303022809e73deaefe4f6ec56c66" 366 | 367 | [[package]] 368 | name = "windows_x86_64_gnu" 369 | version = "0.52.6" 370 | source = "registry+https://github.com/rust-lang/crates.io-index" 371 | checksum = "147a5c80aabfbf0c7d901cb5895d1de30ef2907eb21fbbab29ca94c5b08b1a78" 372 | 373 | [[package]] 374 | name = "windows_x86_64_gnullvm" 375 | version = "0.52.6" 376 | source = "registry+https://github.com/rust-lang/crates.io-index" 377 | checksum = "24d5b23dc417412679681396f2b49f3de8c1473deb516bd34410872eff51ed0d" 378 | 379 | [[package]] 380 | name = "windows_x86_64_msvc" 381 | version = "0.52.6" 382 | source = "registry+https://github.com/rust-lang/crates.io-index" 383 | checksum = "589f6da84c646204747d1270a2a5661ea66ed1cced2631d546fdfb155959f9ec" 384 | -------------------------------------------------------------------------------- /Cargo.toml: -------------------------------------------------------------------------------- 1 | [package] 2 | name = "whirlwind" 3 | description = "Collection of thread-safe, asynchronous data structures." 4 | authors = ["Will Hopkins "] 5 | version = "0.1.1" 6 | edition = "2021" 7 | readme = "README.md" 8 | repository = "https://github.com/fortress-build/whirlwind" 9 | license = "Apache-2.0" 10 | keywords = ["async", "hashmap", "sharding"] 11 | categories = ["asynchronous", "concurrency", "data-structures"] 12 | 13 | 14 | [dependencies] 15 | crossbeam-utils = "0.8.20" 16 | hashbrown = { version = "0.15.1" } 17 | tokio = { version = "1.41.0", features = ["sync"] } 18 | 19 | [dev-dependencies] 20 | tokio = { version = "1.41.0", features = ["full"] } 21 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # 🌀 Whirlwind 2 | 3 | [![Build Status](https://img.shields.io/github/actions/workflow/status/fortress-build/whirlwind/rust.yml?branch=main)](https://github.com/yourusername/shardmap/actions) 4 | [![Crates.io](https://img.shields.io/crates/v/whirlwind)](https://crates.io/crates/whirlwind) 5 | [![Docs.rs](https://docs.rs/whirlwind/badge.svg)](https://docs.rs/whirlwind) 6 | [![License](https://img.shields.io/crates/l/whirlwind)](https://github.com/fortress-build/whirlwind/blob/main/LICENSE) 7 | 8 | An asynchronous, sharded `HashMap` for high-performance concurrent data access 9 | in Rust. 10 | 11 | > [!NOTE] 12 | > This crate is in development, and breaking changes may be made up until a 1.0 release. 13 | 14 | ## 📖 Table of Contents 15 | 16 | - [Features](#-features) 17 | - [Installation](#-installation) 18 | - [Usage](#-usage) 19 | - [Examples](#-examples) 20 | - [Benchmark](#-benchmarks) 21 | - [Contributing](#-contributing) 22 | - [License](#license) 23 | 24 | ## ✨ Features 25 | 26 | - **Async Ready**: Seamless integration with Rust's `async`/`await` syntax. 27 | - **High Performance**: Sharding minimizes lock contention in concurrent environments. 28 | - **Thread-safe**: Safe for use across multiple threads without fear of data races. 29 | - **Familiar API**: Intuitive `HashMap`-like interface for ease of adoption. 30 | - **Customizable Shards**: Configure the number of shards to optimize for your workload. 31 | 32 | ## 📦 Installation 33 | 34 | Add `whirlwind` to your `Cargo.toml`: 35 | 36 | ```toml 37 | [dependencies] 38 | whirlwind = "0.1.1" 39 | ``` 40 | 41 | ## 🔧 Usage 42 | 43 | Here's a quick example to get you started: 44 | 45 | ```rust 46 | use whirlwind::ShardMap; 47 | 48 | #[tokio::main] 49 | async fn main() { 50 | let map = ShardMap::new(); 51 | 52 | map.insert("apple", 3).await; 53 | map.insert("banana", 5).await; 54 | 55 | if let Some(quantity) = map.get(&"apple").await { 56 | println!("We have {} apples!", quantity); 57 | } 58 | 59 | map.remove(&"banana").await; 60 | } 61 | ``` 62 | 63 | ## 📚 Examples 64 | 65 | ### Concurrent Inserts 66 | 67 | ```rust 68 | use whirlwind::ShardMap; 69 | use tokio::task::JoinSet; 70 | 71 | #[tokio::main] 72 | async fn main() { 73 | let map = ShardMap::new(); 74 | let tasks: JoinSet<_> = (0..1000).map(|i| { 75 | let map = map.clone(); 76 | tokio::spawn(async move { 77 | map.insert(i, i * 2).await; 78 | }) 79 | }).collect(); 80 | 81 | tasks.join_all().await.ok(); 82 | 83 | assert_eq!(map.len().await, 1000); 84 | } 85 | ``` 86 | 87 | ### Custom Shard Count 88 | 89 | ```rust 90 | use whirlwind::ShardMap; 91 | 92 | #[tokio::main] 93 | async fn main() { 94 | let map = ShardMap::with_shards(64); // Initialize with 64 shards 95 | // Use the map as needed 96 | } 97 | ``` 98 | 99 | ## 📊 Benchmarks 100 | 101 | Benchmarks were run in a asyncified version of [this benchmark](https://github.com/xacrimon/conc-map-bench). You can 102 | find it [here](https://github.com/willothy/conc-map-bench). Since the benchmarks use [`jonhoo/bustle`](https://github.com/jonhoo/bustle), 103 | an asyncified fork of that library ([here](https://github.com/willothy/bustle)) is required. 104 | 105 | Machine: Apple M3 Max (2023 16-inch MacBook Pro, 36GB RAM) 106 | 107 | OS: macOS 15.0 108 | 109 | See the `results/` directory. 110 | 111 | ### Read Heavy (std hasher) 112 | 113 | | | | 114 | :-------------------------:|:-------------------------: 115 | ![](results/ReadHeavy.std.throughput.svg) | ![](results/ReadHeavy.std.latency.svg) 116 | 117 | ### Exchange (std hasher) 118 | 119 | | | | 120 | :-------------------------:|:-------------------------: 121 | ![](results/Exchange.std.throughput.svg) | ![](results/Exchange.std.latency.svg) 122 | 123 | ### Rapid Grow (std hasher) 124 | 125 | | | | 126 | :-------------------------:|:-------------------------: 127 | ![](results/RapidGrow.std.throughput.svg) | ![](results/RapidGrow.std.latency.svg) 128 | 129 | ### Read Heavy (ahash) 130 | 131 | | | | 132 | :-------------------------:|:-------------------------: 133 | ![](results/ReadHeavy.ahash.throughput.svg) | ![](results/ReadHeavy.ahash.latency.svg) 134 | 135 | ### Exchange (ahash) 136 | 137 | | | | 138 | :-------------------------:|:-------------------------: 139 | ![](results/Exchange.ahash.throughput.svg) | ![](results/Exchange.ahash.latency.svg) 140 | 141 | ### Rapid Grow (ahash) 142 | 143 | | | | 144 | :-------------------------:|:-------------------------: 145 | ![](results/RapidGrow.ahash.throughput.svg) | ![](results/RapidGrow.ahash.latency.svg) 146 | 147 | ## 🤝 Contributing 148 | 149 | Contributions are welcome! Please follow these steps: 150 | 151 | 1. Fork the repository. 152 | 2. Create a new branch: `git checkout -b feature/your-feature`. 153 | 3. Commit your changes: `git commit -am 'Add your feature'`. 154 | 4. Push to the branch: `git push origin feature/your-feature`. 155 | 5. Open a pull request. 156 | 157 | ### Running Tests 158 | 159 | Ensure all tests pass before submitting a PR: 160 | 161 | ```sh 162 | cargo test 163 | ``` 164 | 165 | ### Code Style 166 | 167 | We use `rustfmt` for code formatting: 168 | 169 | ```sh 170 | cargo fmt -- --check 171 | ``` 172 | 173 | ## License 174 | 175 | Copyright 2024 Will Hopkins 176 | 177 | Licensed under the Apache License, Version 2.0 (the "License"); 178 | you may not use this file except in compliance with the License. 179 | You may obtain a copy of the License at 180 | 181 | 182 | 183 | Unless required by applicable law or agreed to in writing, software 184 | distributed under the License is distributed on an "AS IS" BASIS, 185 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 186 | See the License for the specific language governing permissions and 187 | limitations under the License. 188 | 189 | --- 190 | 191 | Made with 💖 and Rust. 192 | -------------------------------------------------------------------------------- /results/Exchange.ahash.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,1961856125,17103411.18923795,58 3 | std::sync::RwLock,33554432,2,1907064458,17594807.485002168,113 4 | std::sync::RwLock,33554432,4,2449463250,13698687.661470324,291 5 | std::sync::RwLock,33554432,6,3823332292,8776226.976192946,683 6 | std::sync::RwLock,33554432,8,3974604208,8442207.134099627,947 7 | std::sync::RwLock,33554432,10,4529053833,7408706.815430781,1349 8 | std::sync::RwLock,33554432,12,4671495208,7182803.47211693,1670 9 | std::sync::RwLock,33554432,14,4755715375,7055601.3878353685,1984 10 | Whirlwind,33554432,1,2659308625,12617727.66220393,79 11 | Whirlwind,33554432,2,2667312750,12579864.134792592,158 12 | Whirlwind,33554432,4,1041210458,32226368.590700425,124 13 | Whirlwind,33554432,6,745400625,45015298.98770879,133 14 | Whirlwind,33554432,8,614593041,54596179.52296339,146 15 | Whirlwind,33554432,10,543906959,61691492.349521495,162 16 | Whirlwind,33554432,12,618545333,54247328.707918644,221 17 | Whirlwind,33554432,14,522493667,64219786.99313115,218 18 | DashMap,33554432,1,1816874750,18468214.168312922,54 19 | DashMap,33554432,2,1775391666,18899734.995151207,105 20 | DashMap,33554432,4,1078015208,31126121.181770932,128 21 | DashMap,33554432,6,907789542,36962787.57086629,162 22 | DashMap,33554432,8,721972125,46476076.89839826,172 23 | DashMap,33554432,10,627028625,53513397.41467146,186 24 | DashMap,33554432,12,549552792,61057704.534417145,196 25 | DashMap,33554432,14,547569875,61278813.0464628,228 26 | Flurry,33554432,1,5762001834,5823398.354718399,171 27 | Flurry,33554432,2,5532963625,6064459.171281829,329 28 | Flurry,33554432,4,3089110333,10862166.896905072,368 29 | Flurry,33554432,6,2453668875,13675207.906771854,438 30 | Flurry,33554432,8,2282568208,14700297.621949531,544 31 | Flurry,33554432,10,2174596250,15430189.397227187,648 32 | Flurry,33554432,12,2305712375,14552739.692868238,824 33 | Flurry,33554432,14,2436477291,13771699.05254003,1016 34 | Contrie,33554432,1,10008375042,3352635.3538101153,298 35 | Contrie,33554432,2,10413623041,3222166.950723217,620 36 | Contrie,33554432,4,4779533250,7020441.169647684,569 37 | Contrie,33554432,6,3530570416,9503969.060618788,631 38 | Contrie,33554432,8,2735428333,12266609.801178806,652 39 | Contrie,33554432,10,2432395625,13794808.564499043,724 40 | Contrie,33554432,12,1974154041,16996866.152857624,706 41 | Contrie,33554432,14,1744712458,19232069.93000104,727 42 | SccMap,33554432,1,3433359875,9773059.982533874,102 43 | SccMap,33554432,2,3423693792,9800652.172342403,204 44 | SccMap,33554432,4,1732266666,19370246.3128734,206 45 | SccMap,33554432,6,1083085709,30980403.232335515,193 46 | SccMap,33554432,8,808901916,41481459.41590278,192 47 | SccMap,33554432,10,685389542,48956731.82010705,204 48 | SccMap,33554432,12,590316959,56841382.393691316,211 49 | SccMap,33554432,14,543821750,61701158.51379611,226 50 | CHashMap,33554432,1,2463606375,13620045.9377363,73 51 | CHashMap,33554432,2,2409286833,13927122.142704211,143 52 | CHashMap,33554432,4,2776520625,12085064.91825538,330 53 | CHashMap,33554432,6,3347246416,10024488.140343715,598 54 | CHashMap,33554432,8,5490261833,6111626.917010827,1308 55 | CHashMap,33554432,10,7244375125,4631791.068384245,2158 56 | CHashMap,33554432,12,10016865542,3349793.59154904,3582 57 | CHashMap,33554432,14,11259991208,2979969.644750721,4698 58 | -------------------------------------------------------------------------------- /results/Exchange.ahash.latency.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exchange.ahash: Latency 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Latency 22 | 23 | 24 | Threads 25 | 26 | 27 | Latency 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 ns 46 | 47 | 48 | 49 | 100 ns 50 | 51 | 52 | 53 | 200 ns 54 | 55 | 56 | 57 | 300 ns 58 | 59 | 60 | 61 | 400 ns 62 | 63 | 64 | 65 | 500 ns 66 | 67 | 68 | 69 | 600 ns 70 | 71 | 72 | 73 | 700 ns 74 | 75 | 76 | 77 | 800 ns 78 | 79 | 80 | 81 | 900 ns 82 | 83 | 84 | 85 | 1000 ns 86 | 87 | 88 | 89 | 1100 ns 90 | 91 | 92 | 93 | 1200 ns 94 | 95 | 96 | 97 | 1300 ns 98 | 99 | 100 | 101 | 1400 ns 102 | 103 | 104 | 105 | 1500 ns 106 | 107 | 108 | 109 | 1600 ns 110 | 111 | 112 | 113 | 1700 ns 114 | 115 | 116 | 117 | 1800 ns 118 | 119 | 120 | 121 | 1900 ns 122 | 123 | 124 | 125 | 2000 ns 126 | 127 | 128 | 129 | 130 | 1 131 | 132 | 133 | 134 | 2 135 | 136 | 137 | 138 | 3 139 | 140 | 141 | 142 | 4 143 | 144 | 145 | 146 | 5 147 | 148 | 149 | 150 | 6 151 | 152 | 153 | 154 | 7 155 | 156 | 157 | 158 | 8 159 | 160 | 161 | 162 | 9 163 | 164 | 165 | 166 | 10 167 | 168 | 169 | 170 | 11 171 | 172 | 173 | 174 | 12 175 | 176 | 177 | 178 | 13 179 | 180 | 181 | 182 | 14 183 | 184 | 185 | 186 | 187 | 0 ns 188 | 189 | 190 | 191 | 100 ns 192 | 193 | 194 | 195 | 200 ns 196 | 197 | 198 | 199 | 300 ns 200 | 201 | 202 | 203 | 400 ns 204 | 205 | 206 | 207 | 500 ns 208 | 209 | 210 | 211 | 600 ns 212 | 213 | 214 | 215 | 700 ns 216 | 217 | 218 | 219 | 800 ns 220 | 221 | 222 | 223 | 900 ns 224 | 225 | 226 | 227 | 1000 ns 228 | 229 | 230 | 231 | 1100 ns 232 | 233 | 234 | 235 | 1200 ns 236 | 237 | 238 | 239 | 1300 ns 240 | 241 | 242 | 243 | 1400 ns 244 | 245 | 246 | 247 | 1500 ns 248 | 249 | 250 | 251 | 1600 ns 252 | 253 | 254 | 255 | 1700 ns 256 | 257 | 258 | 259 | 1800 ns 260 | 261 | 262 | 263 | 1900 ns 264 | 265 | 266 | 267 | 2000 ns 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CHashMap 281 | 282 | 283 | Contrie 284 | 285 | 286 | DashMap 287 | 288 | 289 | Flurry 290 | 291 | 292 | SccMap 293 | 294 | 295 | Whirlwind 296 | 297 | 298 | std::sync::RwLock<StdHashMap> 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | -------------------------------------------------------------------------------- /results/Exchange.ahash.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exchange.ahash: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 10 Mop/s 50 | 51 | 52 | 53 | 20 Mop/s 54 | 55 | 56 | 57 | 30 Mop/s 58 | 59 | 60 | 61 | 40 Mop/s 62 | 63 | 64 | 65 | 50 Mop/s 66 | 67 | 68 | 69 | 60 Mop/s 70 | 71 | 72 | 73 | 74 | 1 75 | 76 | 77 | 78 | 2 79 | 80 | 81 | 82 | 3 83 | 84 | 85 | 86 | 4 87 | 88 | 89 | 90 | 5 91 | 92 | 93 | 94 | 6 95 | 96 | 97 | 98 | 7 99 | 100 | 101 | 102 | 8 103 | 104 | 105 | 106 | 9 107 | 108 | 109 | 110 | 10 111 | 112 | 113 | 114 | 11 115 | 116 | 117 | 118 | 12 119 | 120 | 121 | 122 | 13 123 | 124 | 125 | 126 | 14 127 | 128 | 129 | 130 | 131 | 0 Mop/s 132 | 133 | 134 | 135 | 10 Mop/s 136 | 137 | 138 | 139 | 20 Mop/s 140 | 141 | 142 | 143 | 30 Mop/s 144 | 145 | 146 | 147 | 40 Mop/s 148 | 149 | 150 | 151 | 50 Mop/s 152 | 153 | 154 | 155 | 60 Mop/s 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | CHashMap 169 | 170 | 171 | Contrie 172 | 173 | 174 | DashMap 175 | 176 | 177 | Flurry 178 | 179 | 180 | SccMap 181 | 182 | 183 | Whirlwind 184 | 185 | 186 | std::sync::RwLock<StdHashMap> 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /results/Exchange.std.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,3483532542,9632300.42936111,103 3 | std::sync::RwLock,33554432,2,3823877667,8774975.279563513,227 4 | std::sync::RwLock,33554432,4,4097743791,8188513.902137226,488 5 | std::sync::RwLock,33554432,6,6043054750,5552561.310155266,1080 6 | std::sync::RwLock,33554432,8,6357903417,5277593.854332688,1515 7 | std::sync::RwLock,33554432,10,6791701125,4940504.798788536,2024 8 | std::sync::RwLock,33554432,12,7132900791,4704177.582609532,2550 9 | std::sync::RwLock,33554432,14,7316207584,4586314.9199567605,3052 10 | Whirlwind,33554432,1,3792758333,8846973.377673415,113 11 | Whirlwind,33554432,2,4057374375,8269986.670875053,241 12 | Whirlwind,33554432,4,1449239708,23153127.68120759,172 13 | Whirlwind,33554432,6,1016256708,33017673.32590143,181 14 | Whirlwind,33554432,8,842396458,39832114.29884716,200 15 | Whirlwind,33554432,10,690269834,48610601.74911251,205 16 | Whirlwind,33554432,12,743826458,45110565.29263712,266 17 | Whirlwind,33554432,14,665653333,50408268.59346621,277 18 | DashMap,33554432,1,2978000875,11267435.23874888,88 19 | DashMap,33554432,2,3096797042,10835205.389607836,184 20 | DashMap,33554432,4,1629023583,20597879.82823819,194 21 | DashMap,33554432,6,1333240958,25167567.646837924,238 22 | DashMap,33554432,8,937155667,35804544.732054636,223 23 | DashMap,33554432,10,810836125,41382507.47029802,241 24 | DashMap,33554432,12,746268125,44962970.91611678,266 25 | DashMap,33554432,14,721968833,46476288.81785815,301 26 | Flurry,33554432,1,6217404125,5396855.556658865,185 27 | Flurry,33554432,2,6013292542,5580043.173625462,358 28 | Flurry,33554432,4,3691565625,9089485.440205334,440 29 | Flurry,33554432,6,2727349333,12302946.158749366,487 30 | Flurry,33554432,8,2473950584,13563097.103478767,589 31 | Flurry,33554432,10,2261885583,14834716.774442611,674 32 | Flurry,33554432,12,2288707667,14660864.069190012,818 33 | Flurry,33554432,14,2402579208,13966004.487290975,1002 34 | Contrie,33554432,1,11618745083,2887956.6390603804,346 35 | Contrie,33554432,2,11913509042,2816502.835705826,710 36 | Contrie,33554432,4,5890761583,5696111.025242286,702 37 | Contrie,33554432,6,4125377791,8133662.830396519,737 38 | Contrie,33554432,8,3379919917,9927581.96170007,805 39 | Contrie,33554432,10,2411804666,13912582.753084365,718 40 | Contrie,33554432,12,2073544083,16182164.7656767,741 41 | Contrie,33554432,14,2088591750,16065577.200522793,871 42 | SccMap,33554432,1,4560406416,7357772.299038007,135 43 | SccMap,33554432,2,4194939084,7998788.856787128,250 44 | SccMap,33554432,4,2265411417,14811628.363926444,270 45 | SccMap,33554432,6,1511780166,22195311.695867296,270 46 | SccMap,33554432,8,1091909625,30730045.08042504,260 47 | SccMap,33554432,10,917604500,36567423.11093723,273 48 | SccMap,33554432,12,778302292,43112338.66956157,278 49 | SccMap,33554432,14,678714542,49438209.91535496,283 50 | CHashMap,33554432,1,2374141250,14133292.195651796,70 51 | CHashMap,33554432,2,2450917459,13690559.784779761,146 52 | CHashMap,33554432,4,2554006084,13137960.872610044,304 53 | CHashMap,33554432,6,3385264334,9911908.994223906,605 54 | CHashMap,33554432,8,5701931042,5884748.825063044,1359 55 | CHashMap,33554432,10,6647040542,5048025.777484419,1980 56 | CHashMap,33554432,12,9852920958,3405531.430022865,3523 57 | CHashMap,33554432,14,11202940916,2995144.9580598683,4674 58 | -------------------------------------------------------------------------------- /results/Exchange.std.latency.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exchange.std: Latency 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Latency 22 | 23 | 24 | Threads 25 | 26 | 27 | Latency 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 ns 46 | 47 | 48 | 49 | 100 ns 50 | 51 | 52 | 53 | 200 ns 54 | 55 | 56 | 57 | 300 ns 58 | 59 | 60 | 61 | 400 ns 62 | 63 | 64 | 65 | 500 ns 66 | 67 | 68 | 69 | 600 ns 70 | 71 | 72 | 73 | 700 ns 74 | 75 | 76 | 77 | 800 ns 78 | 79 | 80 | 81 | 900 ns 82 | 83 | 84 | 85 | 1000 ns 86 | 87 | 88 | 89 | 1100 ns 90 | 91 | 92 | 93 | 1200 ns 94 | 95 | 96 | 97 | 1300 ns 98 | 99 | 100 | 101 | 1400 ns 102 | 103 | 104 | 105 | 1500 ns 106 | 107 | 108 | 109 | 1600 ns 110 | 111 | 112 | 113 | 1700 ns 114 | 115 | 116 | 117 | 1800 ns 118 | 119 | 120 | 121 | 1900 ns 122 | 123 | 124 | 125 | 2000 ns 126 | 127 | 128 | 129 | 130 | 1 131 | 132 | 133 | 134 | 2 135 | 136 | 137 | 138 | 3 139 | 140 | 141 | 142 | 4 143 | 144 | 145 | 146 | 5 147 | 148 | 149 | 150 | 6 151 | 152 | 153 | 154 | 7 155 | 156 | 157 | 158 | 8 159 | 160 | 161 | 162 | 9 163 | 164 | 165 | 166 | 10 167 | 168 | 169 | 170 | 11 171 | 172 | 173 | 174 | 12 175 | 176 | 177 | 178 | 13 179 | 180 | 181 | 182 | 14 183 | 184 | 185 | 186 | 187 | 0 ns 188 | 189 | 190 | 191 | 100 ns 192 | 193 | 194 | 195 | 200 ns 196 | 197 | 198 | 199 | 300 ns 200 | 201 | 202 | 203 | 400 ns 204 | 205 | 206 | 207 | 500 ns 208 | 209 | 210 | 211 | 600 ns 212 | 213 | 214 | 215 | 700 ns 216 | 217 | 218 | 219 | 800 ns 220 | 221 | 222 | 223 | 900 ns 224 | 225 | 226 | 227 | 1000 ns 228 | 229 | 230 | 231 | 1100 ns 232 | 233 | 234 | 235 | 1200 ns 236 | 237 | 238 | 239 | 1300 ns 240 | 241 | 242 | 243 | 1400 ns 244 | 245 | 246 | 247 | 1500 ns 248 | 249 | 250 | 251 | 1600 ns 252 | 253 | 254 | 255 | 1700 ns 256 | 257 | 258 | 259 | 1800 ns 260 | 261 | 262 | 263 | 1900 ns 264 | 265 | 266 | 267 | 2000 ns 268 | 269 | 270 | 271 | 272 | 273 | 274 | 275 | 276 | 277 | 278 | 279 | 280 | CHashMap 281 | 282 | 283 | Contrie 284 | 285 | 286 | DashMap 287 | 288 | 289 | Flurry 290 | 291 | 292 | SccMap 293 | 294 | 295 | Whirlwind 296 | 297 | 298 | std::sync::RwLock<StdHashMap> 299 | 300 | 301 | 302 | 303 | 304 | 305 | 306 | 307 | 308 | -------------------------------------------------------------------------------- /results/Exchange.std.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | Exchange.std: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 5 Mop/s 50 | 51 | 52 | 53 | 10 Mop/s 54 | 55 | 56 | 57 | 15 Mop/s 58 | 59 | 60 | 61 | 20 Mop/s 62 | 63 | 64 | 65 | 25 Mop/s 66 | 67 | 68 | 69 | 30 Mop/s 70 | 71 | 72 | 73 | 35 Mop/s 74 | 75 | 76 | 77 | 40 Mop/s 78 | 79 | 80 | 81 | 45 Mop/s 82 | 83 | 84 | 85 | 50 Mop/s 86 | 87 | 88 | 89 | 90 | 1 91 | 92 | 93 | 94 | 2 95 | 96 | 97 | 98 | 3 99 | 100 | 101 | 102 | 4 103 | 104 | 105 | 106 | 5 107 | 108 | 109 | 110 | 6 111 | 112 | 113 | 114 | 7 115 | 116 | 117 | 118 | 8 119 | 120 | 121 | 122 | 9 123 | 124 | 125 | 126 | 10 127 | 128 | 129 | 130 | 11 131 | 132 | 133 | 134 | 12 135 | 136 | 137 | 138 | 13 139 | 140 | 141 | 142 | 14 143 | 144 | 145 | 146 | 147 | 0 Mop/s 148 | 149 | 150 | 151 | 5 Mop/s 152 | 153 | 154 | 155 | 10 Mop/s 156 | 157 | 158 | 159 | 15 Mop/s 160 | 161 | 162 | 163 | 20 Mop/s 164 | 165 | 166 | 167 | 25 Mop/s 168 | 169 | 170 | 171 | 30 Mop/s 172 | 173 | 174 | 175 | 35 Mop/s 176 | 177 | 178 | 179 | 40 Mop/s 180 | 181 | 182 | 183 | 45 Mop/s 184 | 185 | 186 | 187 | 50 Mop/s 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | CHashMap 201 | 202 | 203 | Contrie 204 | 205 | 206 | DashMap 207 | 208 | 209 | Flurry 210 | 211 | 212 | SccMap 213 | 214 | 215 | Whirlwind 216 | 217 | 218 | std::sync::RwLock<StdHashMap> 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /results/RapidGrow.ahash.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,2143215208,15656118.841799485,63 3 | std::sync::RwLock,33554432,2,2219320833,15119234.452750258,132 4 | std::sync::RwLock,33554432,4,2746677750,12216370.122050175,327 5 | std::sync::RwLock,33554432,6,3896292333,8611887.69533736,696 6 | std::sync::RwLock,33554432,8,4437742667,7561148.655490528,1058 7 | std::sync::RwLock,33554432,10,4952410916,6775373.160493212,1475 8 | std::sync::RwLock,33554432,12,5163690084,6498149.860691756,1846 9 | std::sync::RwLock,33554432,14,5354510875,6266572.761419595,2234 10 | Whirlwind,33554432,1,2769117291,12117374.771034934,82 11 | Whirlwind,33554432,2,3195639583,10500067.71054569,190 12 | Whirlwind,33554432,4,1124967666,29827019.046074517,134 13 | Whirlwind,33554432,6,776837333,43193639.87106423,138 14 | Whirlwind,33554432,8,670855459,50017379.37709768,159 15 | Whirlwind,33554432,10,561257000,59784433.86897624,167 16 | Whirlwind,33554432,12,646119250,51932258.634919174,231 17 | Whirlwind,33554432,14,582686250,57585762.49225034,243 18 | DashMap,33554432,1,2296496166,14611142.181197094,68 19 | DashMap,33554432,2,2181702292,15379931.589676308,130 20 | DashMap,33554432,4,1338568166,25067406.24220104,159 21 | DashMap,33554432,6,1034699792,32429147.332813997,185 22 | DashMap,33554432,8,820892083,40875570.24228238,195 23 | DashMap,33554432,10,701636792,47823079.38036408,209 24 | DashMap,33554432,12,593934333,56495188.33254585,212 25 | DashMap,33554432,14,592364333,56644922.94812085,247 26 | Flurry,33554432,1,5851646791,5734186.152795086,174 27 | Flurry,33554432,2,5507423541,6092582.448072882,328 28 | Flurry,33554432,4,3160141958,10618014.141755844,376 29 | Flurry,33554432,6,2375175083,14127140.453839123,424 30 | Flurry,33554432,8,2223936584,15087854.681381509,530 31 | Flurry,33554432,10,2352928750,14260708.914368952,701 32 | Flurry,33554432,12,2484283750,13506682.559912892,888 33 | Flurry,33554432,14,2572453833,13043745.06922395,1073 34 | Contrie,33554432,1,8851528583,3790806.490129141,263 35 | Contrie,33554432,2,8054908791,4165712.2222776012,480 36 | Contrie,33554432,4,4203617584,7982275.10697367,501 37 | Contrie,33554432,6,2974037000,11282452.773788625,531 38 | Contrie,33554432,8,2450935125,13690461.10512615,584 39 | Contrie,33554432,10,2032271167,16510804.534776926,605 40 | Contrie,33554432,12,1700044834,19737380.643691897,607 41 | Contrie,33554432,14,1508406417,22244954.42464032,629 42 | SccMap,33554432,1,3226828292,10398579.956419943,96 43 | SccMap,33554432,2,3209685291,10454119.004778154,191 44 | SccMap,33554432,4,1645198416,20395370.961747874,196 45 | SccMap,33554432,6,1182560625,28374386.302604992,211 46 | SccMap,33554432,8,916597958,36607578.82683391,218 47 | SccMap,33554432,10,666791959,50322190.522996396,198 48 | SccMap,33554432,12,596399375,56261682.031440765,213 49 | SccMap,33554432,14,534770792,62745446.277103335,223 50 | CHashMap,33554432,1,2637066709,12724149.861466398,78 51 | CHashMap,33554432,2,2360051375,14217670.155591423,140 52 | CHashMap,33554432,4,2671766875,12558892.137623347,318 53 | CHashMap,33554432,6,3579899125,9373010.475539587,640 54 | CHashMap,33554432,8,5622563625,5967817.216119098,1340 55 | CHashMap,33554432,10,6992873333,4798375.489178905,2084 56 | CHashMap,33554432,12,10051047083,3338401.6334728776,3594 57 | CHashMap,33554432,14,11580186250,2897572.7398166847,4831 58 | -------------------------------------------------------------------------------- /results/RapidGrow.ahash.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RapidGrow.ahash: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 10 Mop/s 50 | 51 | 52 | 53 | 20 Mop/s 54 | 55 | 56 | 57 | 30 Mop/s 58 | 59 | 60 | 61 | 40 Mop/s 62 | 63 | 64 | 65 | 50 Mop/s 66 | 67 | 68 | 69 | 60 Mop/s 70 | 71 | 72 | 73 | 74 | 1 75 | 76 | 77 | 78 | 2 79 | 80 | 81 | 82 | 3 83 | 84 | 85 | 86 | 4 87 | 88 | 89 | 90 | 5 91 | 92 | 93 | 94 | 6 95 | 96 | 97 | 98 | 7 99 | 100 | 101 | 102 | 8 103 | 104 | 105 | 106 | 9 107 | 108 | 109 | 110 | 10 111 | 112 | 113 | 114 | 11 115 | 116 | 117 | 118 | 12 119 | 120 | 121 | 122 | 13 123 | 124 | 125 | 126 | 14 127 | 128 | 129 | 130 | 131 | 0 Mop/s 132 | 133 | 134 | 135 | 10 Mop/s 136 | 137 | 138 | 139 | 20 Mop/s 140 | 141 | 142 | 143 | 30 Mop/s 144 | 145 | 146 | 147 | 40 Mop/s 148 | 149 | 150 | 151 | 50 Mop/s 152 | 153 | 154 | 155 | 60 Mop/s 156 | 157 | 158 | 159 | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | CHashMap 169 | 170 | 171 | Contrie 172 | 173 | 174 | DashMap 175 | 176 | 177 | Flurry 178 | 179 | 180 | SccMap 181 | 182 | 183 | Whirlwind 184 | 185 | 186 | std::sync::RwLock<StdHashMap> 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | -------------------------------------------------------------------------------- /results/RapidGrow.std.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,4151997459,8081515.543143302,123 3 | std::sync::RwLock,33554432,2,4070890084,8242529.5961393,242 4 | std::sync::RwLock,33554432,4,4447226875,7545023.661514907,530 5 | std::sync::RwLock,33554432,6,5888013041,5698769.986810564,1052 6 | std::sync::RwLock,33554432,8,6790618292,4941292.612416508,1619 7 | std::sync::RwLock,33554432,10,7266773666,4617514.393904339,2165 8 | std::sync::RwLock,33554432,12,7503865625,4471619.5194393555,2683 9 | std::sync::RwLock,33554432,14,7732148083,4339600.28181214,3226 10 | Whirlwind,33554432,1,4216191375,7958469.864285987,125 11 | Whirlwind,33554432,2,5105755375,6571883.988860316,304 12 | Whirlwind,33554432,4,1627183250,20621175.88784177,193 13 | Whirlwind,33554432,6,1114935417,30095404.171737775,199 14 | Whirlwind,33554432,8,896436083,37430925.23418649,213 15 | Whirlwind,33554432,10,817010583,41069764.20891723,243 16 | Whirlwind,33554432,12,812290208,41308428.526569165,290 17 | Whirlwind,33554432,14,724345875,46323770.39490975,302 18 | DashMap,33554432,1,3826368417,8769263.26563917,114 19 | DashMap,33554432,2,3445861917,9737602.030557511,205 20 | DashMap,33554432,4,1933775583,17351771.474921968,230 21 | DashMap,33554432,6,1390503625,24131135.940044746,248 22 | DashMap,33554432,8,1051723791,31904224.55699683,250 23 | DashMap,33554432,10,890352625,37686677.23083312,265 24 | DashMap,33554432,12,819605667,40939726.68932266,293 25 | DashMap,33554432,14,759618167,44172761.339448065,316 26 | Flurry,33554432,1,6458796291,5195152.546730166,192 27 | Flurry,33554432,2,5935701709,5652984.877781701,353 28 | Flurry,33554432,4,3693605667,9084465.160909664,440 29 | Flurry,33554432,6,2729682375,12292430.909658492,488 30 | Flurry,33554432,8,2364447250,14191237.296581686,563 31 | Flurry,33554432,10,2378707917,14106158.9614241,708 32 | Flurry,33554432,12,2399580916,13983455.100957302,858 33 | Flurry,33554432,14,2494113375,13453450.96832256,1040 34 | Contrie,33554432,1,9808430042,3420978.877997691,292 35 | Contrie,33554432,2,10166340417,3300541.8492470295,605 36 | Contrie,33554432,4,5056863166,6635424.154959228,602 37 | Contrie,33554432,6,3486944291,9622875.847660052,623 38 | Contrie,33554432,8,2803121084,11970382.653652076,668 39 | Contrie,33554432,10,2478183958,13539927.853895018,738 40 | Contrie,33554432,12,2006323500,16724337.824882178,717 41 | Contrie,33554432,14,1864639583,17995130.161301527,777 42 | SccMap,33554432,1,4367411000,7682911.454864221,130 43 | SccMap,33554432,2,4980319916,6737404.939028419,296 44 | SccMap,33554432,4,2222010875,15100930.592880199,264 45 | SccMap,33554432,6,1501729542,22343858.239155553,268 46 | SccMap,33554432,8,1085681375,30906334.743008737,258 47 | SccMap,33554432,10,857740708,39119551.73287636,255 48 | SccMap,33554432,12,760097166,44144924.49245627,271 49 | SccMap,33554432,14,666946125,50310558.44278277,278 50 | CHashMap,33554432,1,2595581291,12927521.136150768,77 51 | CHashMap,33554432,2,2639164750,12714034.620233541,157 52 | CHashMap,33554432,4,2528907583,13268350.423543334,301 53 | CHashMap,33554432,6,2932385000,11442710.285313832,524 54 | CHashMap,33554432,8,5006372292,6702344.5407004105,1193 55 | CHashMap,33554432,10,6876338458,4879694.652168036,2049 56 | CHashMap,33554432,12,8688601000,3861891.2296697707,3107 57 | CHashMap,33554432,14,11479123500,2923083.1082181493,4789 58 | -------------------------------------------------------------------------------- /results/RapidGrow.std.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | RapidGrow.std: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 5 Mop/s 50 | 51 | 52 | 53 | 10 Mop/s 54 | 55 | 56 | 57 | 15 Mop/s 58 | 59 | 60 | 61 | 20 Mop/s 62 | 63 | 64 | 65 | 25 Mop/s 66 | 67 | 68 | 69 | 30 Mop/s 70 | 71 | 72 | 73 | 35 Mop/s 74 | 75 | 76 | 77 | 40 Mop/s 78 | 79 | 80 | 81 | 45 Mop/s 82 | 83 | 84 | 85 | 50 Mop/s 86 | 87 | 88 | 89 | 90 | 1 91 | 92 | 93 | 94 | 2 95 | 96 | 97 | 98 | 3 99 | 100 | 101 | 102 | 4 103 | 104 | 105 | 106 | 5 107 | 108 | 109 | 110 | 6 111 | 112 | 113 | 114 | 7 115 | 116 | 117 | 118 | 8 119 | 120 | 121 | 122 | 9 123 | 124 | 125 | 126 | 10 127 | 128 | 129 | 130 | 11 131 | 132 | 133 | 134 | 12 135 | 136 | 137 | 138 | 13 139 | 140 | 141 | 142 | 14 143 | 144 | 145 | 146 | 147 | 0 Mop/s 148 | 149 | 150 | 151 | 5 Mop/s 152 | 153 | 154 | 155 | 10 Mop/s 156 | 157 | 158 | 159 | 15 Mop/s 160 | 161 | 162 | 163 | 20 Mop/s 164 | 165 | 166 | 167 | 25 Mop/s 168 | 169 | 170 | 171 | 30 Mop/s 172 | 173 | 174 | 175 | 35 Mop/s 176 | 177 | 178 | 179 | 40 Mop/s 180 | 181 | 182 | 183 | 45 Mop/s 184 | 185 | 186 | 187 | 50 Mop/s 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | CHashMap 201 | 202 | 203 | Contrie 204 | 205 | 206 | DashMap 207 | 208 | 209 | Flurry 210 | 211 | 212 | SccMap 213 | 214 | 215 | Whirlwind 216 | 217 | 218 | std::sync::RwLock<StdHashMap> 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | -------------------------------------------------------------------------------- /results/ReadHeavy.ahash.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,1402586208,23923258.19875736,41 3 | std::sync::RwLock,33554432,2,1456291208,23041018.043418687,86 4 | std::sync::RwLock,33554432,4,1805765792,18581829.464626387,215 5 | std::sync::RwLock,33554432,6,2910740042,11527801.011369053,520 6 | std::sync::RwLock,33554432,8,3538722208,9482075.7402611,843 7 | std::sync::RwLock,33554432,10,3939641792,8517127.640420767,1174 8 | std::sync::RwLock,33554432,12,3892529584,8620212.45462678,1392 9 | std::sync::RwLock,33554432,14,3727431750,9002024.517283248,1555 10 | Whirlwind,33554432,1,1675872125,20022071.791426208,49 11 | Whirlwind,33554432,2,1673813541,20046696.467728004,99 12 | Whirlwind,33554432,4,558996375,60026206.78890807,66 13 | Whirlwind,33554432,6,500019125,67106297.1841327,89 14 | Whirlwind,33554432,8,406531375,82538357.58679143,96 15 | Whirlwind,33554432,10,344283292,97461691.51885535,102 16 | Whirlwind,33554432,12,343057750,97809864.37414692,122 17 | Whirlwind,33554432,14,348910333,96169212.62116934,145 18 | DashMap,33554432,1,1348629791,24880387.652655672,40 19 | DashMap,33554432,2,1246438750,26920241.36765645,74 20 | DashMap,33554432,4,785165625,42735482.72060433,93 21 | DashMap,33554432,6,647500250,51821496.59401676,115 22 | DashMap,33554432,8,495386083,67733901.1964129,118 23 | DashMap,33554432,10,448623042,74794267.92349198,133 24 | DashMap,33554432,12,408236583,82193594.10031119,145 25 | DashMap,33554432,14,368153041,91142618.05051883,153 26 | Flurry,33554432,1,3331005375,10073364.7119978,99 27 | Flurry,33554432,2,3162491625,10610125.17305876,188 28 | Flurry,33554432,4,1617588000,20743497.10803987,192 29 | Flurry,33554432,6,1162127959,28873267.99096484,207 30 | Flurry,33554432,8,898905250,37328107.71769327,214 31 | Flurry,33554432,10,702003375,47798106.3837478,209 32 | Flurry,33554432,12,621483416,53990872.7025469,222 33 | Flurry,33554432,14,531872000,63087419.529510856,221 34 | Contrie,33554432,1,4114397459,8155369.609856645,122 35 | Contrie,33554432,2,3892825000,8619558.289930834,232 36 | Contrie,33554432,4,2142954125,15658026.277160738,255 37 | Contrie,33554432,6,1497614375,22405255.02434497,267 38 | Contrie,33554432,8,1046360708,32067748.476656295,249 39 | Contrie,33554432,10,955138333,35130442.1995175,284 40 | Contrie,33554432,12,806302959,41615166.63862324,288 41 | Contrie,33554432,14,747380792,44896032.06179267,311 42 | SccMap,33554432,1,2236813084,15000999.520262105,66 43 | SccMap,33554432,2,2310149667,14524787.064369885,137 44 | SccMap,33554432,4,1261678667,26595069.630356207,150 45 | SccMap,33554432,6,897200791,37399021.865106665,160 46 | SccMap,33554432,8,649000125,51701734.26391867,154 47 | SccMap,33554432,10,505558125,66371066.63056795,150 48 | SccMap,33554432,12,467804959,71727396.97271998,167 49 | SccMap,33554432,14,388192125,86437693.70643467,161 50 | CHashMap,33554432,1,2069160833,16216444.591864163,61 51 | CHashMap,33554432,2,2031126791,16520107.040427491,121 52 | CHashMap,33554432,4,1872315250,17921358.061896894,223 53 | CHashMap,33554432,6,2199297209,15256888.365377814,393 54 | CHashMap,33554432,8,3457962833,9703525.92566457,824 55 | CHashMap,33554432,10,3831804417,8756822.725902714,1141 56 | CHashMap,33554432,12,5905773542,5681632.009993518,2112 57 | CHashMap,33554432,14,7023594959,4777387.106727092,2930 58 | -------------------------------------------------------------------------------- /results/ReadHeavy.ahash.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ReadHeavy.ahash: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 10 Mop/s 50 | 51 | 52 | 53 | 20 Mop/s 54 | 55 | 56 | 57 | 30 Mop/s 58 | 59 | 60 | 61 | 40 Mop/s 62 | 63 | 64 | 65 | 50 Mop/s 66 | 67 | 68 | 69 | 60 Mop/s 70 | 71 | 72 | 73 | 70 Mop/s 74 | 75 | 76 | 77 | 80 Mop/s 78 | 79 | 80 | 81 | 90 Mop/s 82 | 83 | 84 | 85 | 86 | 1 87 | 88 | 89 | 90 | 2 91 | 92 | 93 | 94 | 3 95 | 96 | 97 | 98 | 4 99 | 100 | 101 | 102 | 5 103 | 104 | 105 | 106 | 6 107 | 108 | 109 | 110 | 7 111 | 112 | 113 | 114 | 8 115 | 116 | 117 | 118 | 9 119 | 120 | 121 | 122 | 10 123 | 124 | 125 | 126 | 11 127 | 128 | 129 | 130 | 12 131 | 132 | 133 | 134 | 13 135 | 136 | 137 | 138 | 14 139 | 140 | 141 | 142 | 143 | 0 Mop/s 144 | 145 | 146 | 147 | 10 Mop/s 148 | 149 | 150 | 151 | 20 Mop/s 152 | 153 | 154 | 155 | 30 Mop/s 156 | 157 | 158 | 159 | 40 Mop/s 160 | 161 | 162 | 163 | 50 Mop/s 164 | 165 | 166 | 167 | 60 Mop/s 168 | 169 | 170 | 171 | 70 Mop/s 172 | 173 | 174 | 175 | 80 Mop/s 176 | 177 | 178 | 179 | 90 Mop/s 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | CHashMap 193 | 194 | 195 | Contrie 196 | 197 | 198 | DashMap 199 | 200 | 201 | Flurry 202 | 203 | 204 | SccMap 205 | 206 | 207 | Whirlwind 208 | 209 | 210 | std::sync::RwLock<StdHashMap> 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /results/ReadHeavy.std.csv: -------------------------------------------------------------------------------- 1 | name,total_ops,threads,spent,throughput,latency 2 | std::sync::RwLock,33554432,1,2088434458,16066787.191460906,62 3 | std::sync::RwLock,33554432,2,2018787500,16621081.713652376,120 4 | std::sync::RwLock,33554432,4,2686261750,12491125.259852285,320 5 | std::sync::RwLock,33554432,6,4237735417,7918010.139423483,757 6 | std::sync::RwLock,33554432,8,4989200125,6725413.124212972,1189 7 | std::sync::RwLock,33554432,10,5366934000,6252067.19516208,1599 8 | std::sync::RwLock,33554432,12,5420637167,6190126.910591654,1938 9 | std::sync::RwLock,33554432,14,5103008833,6575421.109015353,2129 10 | Whirlwind,33554432,1,2046832125,16393348.33089939,61 11 | Whirlwind,33554432,2,2069758584,16211761.245677723,123 12 | Whirlwind,33554432,4,701719917,47817414.30890581,83 13 | Whirlwind,33554432,6,589363125,56933375.327816784,105 14 | Whirlwind,33554432,8,462469083,72554973.36672774,110 15 | Whirlwind,33554432,10,417213333,80425119.1080703,124 16 | Whirlwind,33554432,12,398403875,84222152.70873055,142 17 | Whirlwind,33554432,14,357985584,93731238.07130736,149 18 | DashMap,33554432,1,1976486458,16976808.449248683,58 19 | DashMap,33554432,2,2099995666,15978333.92861869,125 20 | DashMap,33554432,4,1209112416,27751292.23385628,144 21 | DashMap,33554432,6,910960291,36834132.433111735,162 22 | DashMap,33554432,8,648372667,51751768.24657848,154 23 | DashMap,33554432,10,585138084,57344467.77181572,174 24 | DashMap,33554432,12,541303625,61988190.084631346,193 25 | DashMap,33554432,14,462796750,72503603.36367963,193 26 | Flurry,33554432,1,3721671875,9015956.571937175,110 27 | Flurry,33554432,2,3617322167,9276041.903624007,215 28 | Flurry,33554432,4,1942989250,17269489.267632335,231 29 | Flurry,33554432,6,1306239291,25687814.04080426,233 30 | Flurry,33554432,8,969485750,34610546.88013723,231 31 | Flurry,33554432,10,807761417,41540028.14917811,240 32 | Flurry,33554432,12,677527125,49524854.078720465,242 33 | Flurry,33554432,14,608441709,55148145.670598656,253 34 | Contrie,33554432,1,6138156917,5466532.129061243,182 35 | Contrie,33554432,2,6066862292,5530771.984761575,361 36 | Contrie,33554432,4,2927608875,11461378.016214684,348 37 | Contrie,33554432,6,2168754584,15471751.505471399,387 38 | Contrie,33554432,8,1480905375,22658052.679429296,353 39 | Contrie,33554432,10,1215291667,27610188.493129853,362 40 | Contrie,33554432,12,1150018500,29177297.582604103,411 41 | Contrie,33554432,14,1079408375,31085947.42930357,450 42 | SccMap,33554432,1,3048552750,11006675.872674339,90 43 | SccMap,33554432,2,3181834666,10545623.994405245,189 44 | SccMap,33554432,4,1783206375,18816908.95143867,212 45 | SccMap,33554432,6,1276808417,26279927.006464902,228 46 | SccMap,33554432,8,869990333,38568741.20002435,207 47 | SccMap,33554432,10,741915083,45226782.37557815,221 48 | SccMap,33554432,12,667159084,50294499.17525218,238 49 | SccMap,33554432,14,519699042,64565121.90376521,216 50 | CHashMap,33554432,1,2050865458,16361108.36481795,61 51 | CHashMap,33554432,2,2054465375,16332439.77158778,122 52 | CHashMap,33554432,4,1879542666,17852444.96280033,224 53 | CHashMap,33554432,6,1872948208,17915301.585317515,334 54 | CHashMap,33554432,8,3558958916,9428159.411773328,848 55 | CHashMap,33554432,10,3821885541,8779549.162327988,1139 56 | CHashMap,33554432,12,5524990291,6073211.034354015,1975 57 | CHashMap,33554432,14,6791308750,4940790.2416452505,2833 58 | -------------------------------------------------------------------------------- /results/ReadHeavy.std.throughput.svg: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ReadHeavy.std: Throughput 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | Throughput 22 | 23 | 24 | Threads 25 | 26 | 27 | Throughput 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 0 Mop/s 46 | 47 | 48 | 49 | 10 Mop/s 50 | 51 | 52 | 53 | 20 Mop/s 54 | 55 | 56 | 57 | 30 Mop/s 58 | 59 | 60 | 61 | 40 Mop/s 62 | 63 | 64 | 65 | 50 Mop/s 66 | 67 | 68 | 69 | 60 Mop/s 70 | 71 | 72 | 73 | 70 Mop/s 74 | 75 | 76 | 77 | 80 Mop/s 78 | 79 | 80 | 81 | 90 Mop/s 82 | 83 | 84 | 85 | 86 | 1 87 | 88 | 89 | 90 | 2 91 | 92 | 93 | 94 | 3 95 | 96 | 97 | 98 | 4 99 | 100 | 101 | 102 | 5 103 | 104 | 105 | 106 | 6 107 | 108 | 109 | 110 | 7 111 | 112 | 113 | 114 | 8 115 | 116 | 117 | 118 | 9 119 | 120 | 121 | 122 | 10 123 | 124 | 125 | 126 | 11 127 | 128 | 129 | 130 | 12 131 | 132 | 133 | 134 | 13 135 | 136 | 137 | 138 | 14 139 | 140 | 141 | 142 | 143 | 0 Mop/s 144 | 145 | 146 | 147 | 10 Mop/s 148 | 149 | 150 | 151 | 20 Mop/s 152 | 153 | 154 | 155 | 30 Mop/s 156 | 157 | 158 | 159 | 40 Mop/s 160 | 161 | 162 | 163 | 50 Mop/s 164 | 165 | 166 | 167 | 60 Mop/s 168 | 169 | 170 | 171 | 70 Mop/s 172 | 173 | 174 | 175 | 80 Mop/s 176 | 177 | 178 | 179 | 90 Mop/s 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | CHashMap 193 | 194 | 195 | Contrie 196 | 197 | 198 | DashMap 199 | 200 | 201 | Flurry 202 | 203 | 204 | SccMap 205 | 206 | 207 | Whirlwind 208 | 209 | 210 | std::sync::RwLock<StdHashMap> 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | -------------------------------------------------------------------------------- /src/lib.rs: -------------------------------------------------------------------------------- 1 | //! # Whirlwind 2 | //! 3 | //! A collection of data structures that allow for concurrent access to shared data. 4 | //! 5 | //! Currently, this crate provides the following data structures: 6 | //! 7 | //! - [`ShardMap`]: A concurrent hashmap using a sharding strategy. 8 | //! - [`ShardSet`]: A concurrent set based on a [`ShardMap`] with values of `()`. 9 | //! 10 | //! ## ShardMap 11 | //! 12 | //! A concurrent hashmap using a sharding strategy. 13 | //! 14 | //! ### Example 15 | //! 16 | //! ```rust 17 | //! use tokio::runtime::Runtime; 18 | //! use std::sync::Arc; 19 | //! use whirlwind::ShardMap; 20 | //! 21 | //! let rt = Runtime::new().unwrap(); 22 | //! let map = Arc::new(ShardMap::new()); 23 | //! 24 | //! rt.block_on(async { 25 | //! map.insert("foo", "bar").await; 26 | //! assert_eq!(map.len().await, 1); 27 | //! assert_eq!(map.contains_key(&"foo").await, true); 28 | //! }); 29 | //! ``` 30 | //! 31 | //! ## ShardSet 32 | //! 33 | //! A concurrent set based on a [`ShardMap`] with values of `()`. 34 | //! 35 | //! ### Example 36 | //! 37 | //! ```rust 38 | //! use tokio::runtime::Runtime; 39 | //! use std::sync::Arc; 40 | //! use whirlwind::ShardSet; 41 | //! 42 | //! let rt = Runtime::new().unwrap(); 43 | //! let set = Arc::new(ShardSet::new()); 44 | //! rt.block_on(async { 45 | //! set.insert("foo").await; 46 | //! assert_eq!(set.contains(&"foo").await, true); 47 | //! set.remove(&"foo").await; 48 | //! assert_eq!(set.contains(&"foo").await, false); 49 | //! assert_eq!(set.len().await, 0); 50 | //! }); 51 | //! ``` 52 | //! 53 | //! 54 | //! See the documentation for each data structure for more information. 55 | 56 | pub mod mapref; 57 | mod shard; 58 | mod shard_map; 59 | mod shard_set; 60 | 61 | pub use shard_map::ShardMap; 62 | pub use shard_set::ShardSet; 63 | -------------------------------------------------------------------------------- /src/mapref.rs: -------------------------------------------------------------------------------- 1 | //! This module contains the `MapRef` and `MapRefMut` types, which are used to hold references to 2 | //! key-value pairs in a [`ShardMap`]. These types are used to ensure that the shard associated with 3 | //! the key is locked for the duration of the reference. 4 | //! 5 | //! # Example 6 | //! ``` 7 | //! use whirlwind::ShardMap; 8 | //! use tokio::runtime::Runtime; 9 | //! use std::sync::Arc; 10 | //! 11 | //! let rt = Runtime::new().unwrap(); 12 | //! let map = Arc::new(ShardMap::new()); 13 | //! rt.block_on(async { 14 | //! map.insert("foo", "bar").await; 15 | //! 16 | //! let r = map.get(&"foo").await.unwrap(); 17 | //! 18 | //! assert_eq!(r.key(), &"foo"); 19 | //! assert_eq!(r.value(), &"bar"); 20 | //! 21 | //! drop(r); // release the lock so we can mutate the value. 22 | //! 23 | //! let mut mr = map.get_mut(&"foo").await.unwrap(); 24 | //! *mr.value_mut() = "baz"; 25 | //! 26 | //! assert_eq!(mr.value(), &"baz"); 27 | //! }); 28 | 29 | use crate::shard::{ShardReader, ShardWriter}; 30 | 31 | /// A reference to a key-value pair in a [`crate::ShardMap`]. 32 | /// 33 | /// Holds a shared (read-only) lock on the shard associated with the key. Dropping this 34 | /// reference will release the lock. 35 | pub struct MapRef<'a, K, V> { 36 | key: &'a K, 37 | value: &'a V, 38 | #[allow(unused)] 39 | reader: ShardReader<'a, K, V>, 40 | } 41 | 42 | impl std::ops::Deref for MapRef<'_, K, V> 43 | where 44 | K: Eq + std::hash::Hash, 45 | { 46 | type Target = V; 47 | 48 | fn deref(&self) -> &Self::Target { 49 | self.value 50 | } 51 | } 52 | 53 | impl<'a, K, V> MapRef<'a, K, V> 54 | where 55 | K: Eq + std::hash::Hash, 56 | { 57 | pub(crate) fn new(reader: ShardReader<'a, K, V>, key: &'a K, value: &'a V) -> Self { 58 | Self { reader, key, value } 59 | } 60 | 61 | /// Returns a reference to the key. 62 | pub fn key(&self) -> &K { 63 | self.key 64 | } 65 | 66 | /// Returns a reference to the value. 67 | pub fn value(&self) -> &V { 68 | self.value 69 | } 70 | 71 | /// Returns a reference to the key-value pair 72 | pub fn pair(&self) -> (&K, &V) { 73 | (self.key, self.value) 74 | } 75 | } 76 | 77 | /// A mutable reference to a key-value pair in a [`crate::ShardMap`]. 78 | /// 79 | /// Holds an exclusive lock on the shard associated with the key. Dropping this 80 | /// reference will release the lock. 81 | pub struct MapRefMut<'a, K, V> { 82 | key: &'a K, 83 | value: &'a mut V, 84 | #[allow(unused)] 85 | writer: ShardWriter<'a, K, V>, 86 | } 87 | 88 | impl<'a, K, V> std::ops::Deref for MapRefMut<'a, K, V> 89 | where 90 | K: Eq + std::hash::Hash, 91 | { 92 | type Target = V; 93 | 94 | fn deref(&self) -> &Self::Target { 95 | self.value 96 | } 97 | } 98 | 99 | impl<'a, K, V> std::ops::DerefMut for MapRefMut<'a, K, V> 100 | where 101 | K: Eq + std::hash::Hash, 102 | { 103 | fn deref_mut(&mut self) -> &mut Self::Target { 104 | self.value 105 | } 106 | } 107 | 108 | impl<'a, K, V> MapRefMut<'a, K, V> 109 | where 110 | K: Eq + std::hash::Hash, 111 | { 112 | pub(crate) fn new(writer: ShardWriter<'a, K, V>, key: &'a K, value: &'a mut V) -> Self { 113 | Self { writer, key, value } 114 | } 115 | 116 | /// Returns a reference to the key. 117 | pub fn key(&self) -> &K { 118 | self.key 119 | } 120 | 121 | /// returns a reference to the value. 122 | pub fn value(&self) -> &V { 123 | self.value 124 | } 125 | 126 | /// Returns a mutable reference to the value. 127 | pub fn value_mut(&mut self) -> &mut V { 128 | self.value 129 | } 130 | 131 | /// Returns a reference to the key-value pair. 132 | pub fn pair(&self) -> (&K, &V) { 133 | (self.key, self.value) 134 | } 135 | 136 | /// Returns a reference to the key-value pair, with a mutable reference to the value. 137 | pub fn pair_mut(&mut self) -> (&K, &mut V) { 138 | (self.key, self.value) 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /src/shard.rs: -------------------------------------------------------------------------------- 1 | use tokio::sync::{RwLock, RwLockReadGuard, RwLockWriteGuard}; 2 | 3 | pub(crate) type Inner = hashbrown::HashTable<(K, V)>; 4 | pub(crate) type ShardReader<'a, K, V> = RwLockReadGuard<'a, Inner>; 5 | pub(crate) type ShardWriter<'a, K, V> = RwLockWriteGuard<'a, Inner>; 6 | 7 | /// A shard in a [`crate::ShardMap`]. Each shard contains a [`hashbrown::HashTable`] of key-value pairs. 8 | pub(crate) struct Shard { 9 | data: RwLock>, 10 | } 11 | 12 | impl Shard 13 | where 14 | K: Eq + std::hash::Hash, 15 | { 16 | pub fn with_capacity(capacity: usize) -> Self { 17 | Self { 18 | data: RwLock::new(Inner::with_capacity(capacity)), 19 | } 20 | } 21 | 22 | pub async fn write<'a>(&'a self) -> ShardWriter<'a, K, V> { 23 | self.data.write().await 24 | } 25 | 26 | pub async fn read<'a>(&'a self) -> ShardReader<'a, K, V> { 27 | self.data.read().await 28 | } 29 | } 30 | 31 | impl std::ops::Deref for Shard { 32 | type Target = RwLock>; 33 | 34 | fn deref(&self) -> &Self::Target { 35 | &self.data 36 | } 37 | } 38 | 39 | impl std::ops::DerefMut for Shard { 40 | fn deref_mut(&mut self) -> &mut Self::Target { 41 | &mut self.data 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/shard_map.rs: -------------------------------------------------------------------------------- 1 | //! A concurrent hashmap using a sharding strategy. 2 | //! 3 | //! # Examples 4 | //! ``` 5 | //! use tokio::runtime::Runtime; 6 | //! use std::sync::Arc; 7 | //! use whirlwind::ShardMap; 8 | //! 9 | //! let rt = Runtime::new().unwrap(); 10 | //! let map = Arc::new(ShardMap::new()); 11 | //! rt.block_on(async { 12 | //! map.insert("foo", "bar").await; 13 | //! assert_eq!(map.len().await, 1); 14 | //! assert_eq!(map.contains_key(&"foo").await, true); 15 | //! assert_eq!(map.contains_key(&"bar").await, false); 16 | //! 17 | //! assert_eq!(map.get(&"foo").await.unwrap().value(), &"bar"); 18 | //! assert_eq!(map.remove(&"foo").await, Some("bar")); 19 | //! }); 20 | //! ``` 21 | use std::{ 22 | hash::{BuildHasher, RandomState}, 23 | sync::{Arc, OnceLock}, 24 | }; 25 | 26 | use crossbeam_utils::CachePadded; 27 | use hashbrown::hash_table::Entry; 28 | 29 | use crate::{ 30 | mapref::{MapRef, MapRefMut}, 31 | shard::Shard, 32 | }; 33 | 34 | struct Inner { 35 | shards: Box<[CachePadded>]>, 36 | hasher: S, 37 | shift: usize, 38 | } 39 | 40 | impl std::ops::Deref for Inner { 41 | type Target = Box<[CachePadded>]>; 42 | 43 | fn deref(&self) -> &Self::Target { 44 | &self.shards 45 | } 46 | } 47 | 48 | impl std::ops::DerefMut for Inner { 49 | fn deref_mut(&mut self) -> &mut Self::Target { 50 | &mut self.shards 51 | } 52 | } 53 | 54 | /// A concurrent hashmap using a sharding strategy. 55 | /// 56 | /// # Examples 57 | /// ``` 58 | /// use tokio::runtime::Runtime; 59 | /// use std::sync::Arc; 60 | /// use whirlwind::ShardMap; 61 | /// 62 | /// let rt = Runtime::new().unwrap(); 63 | /// let map = Arc::new(ShardMap::new()); 64 | /// rt.block_on(async { 65 | /// map.insert("foo", "bar").await; 66 | /// assert_eq!(map.len().await, 1); 67 | /// assert_eq!(map.contains_key(&"foo").await, true); 68 | /// assert_eq!(map.contains_key(&"bar").await, false); 69 | /// 70 | /// assert_eq!(map.get(&"foo").await.unwrap().value(), &"bar"); 71 | /// assert_eq!(map.remove(&"foo").await, Some("bar")); 72 | /// }); 73 | /// ``` 74 | pub struct ShardMap { 75 | inner: Arc>, 76 | } 77 | 78 | impl Clone for ShardMap { 79 | fn clone(&self) -> Self { 80 | Self { 81 | inner: Arc::clone(&self.inner), 82 | } 83 | } 84 | } 85 | 86 | impl Default for ShardMap 87 | where 88 | K: Eq + std::hash::Hash + 'static, 89 | V: 'static, 90 | { 91 | fn default() -> Self { 92 | Self::new() 93 | } 94 | } 95 | 96 | #[inline(always)] 97 | fn calculate_shard_count() -> usize { 98 | (std::thread::available_parallelism().map_or(1, usize::from) * 4).next_power_of_two() 99 | } 100 | 101 | #[inline(always)] 102 | fn shard_count() -> usize { 103 | static SHARD_COUNT: OnceLock = OnceLock::new(); 104 | *SHARD_COUNT.get_or_init(calculate_shard_count) 105 | } 106 | 107 | impl ShardMap 108 | where 109 | K: Eq + std::hash::Hash + 'static, 110 | V: 'static, 111 | { 112 | /// Creates a new `ShardMap` with the default hasher. 113 | pub fn new() -> Self { 114 | Self::with_shards(shard_count()) 115 | } 116 | 117 | /// Creates a new `ShardMap` with the default hasher and `shards` shards. 118 | pub fn with_shards(shards: usize) -> Self { 119 | Self::with_shards_and_hasher(shards, RandomState::new()) 120 | } 121 | 122 | /// Creates a new `ShardMap` with the default hasher and space for at least `cap` elements. 123 | pub fn with_capacity(capacity: usize) -> Self { 124 | Self::with_capacity_and_hasher(capacity, RandomState::new()) 125 | } 126 | 127 | /// Creates a new `ShardMap` with the default hasher, `shards` shards, and space for at least `cap` elements. 128 | pub fn with_shards_and_capacity(shards: usize, cap: usize) -> Self { 129 | Self::with_shards_and_capacity_and_hasher(shards, cap, RandomState::new()) 130 | } 131 | } 132 | 133 | fn ptr_size_bits() -> usize { 134 | std::mem::size_of::<*const ()>() * 8 135 | } 136 | 137 | impl ShardMap 138 | where 139 | K: Eq + std::hash::Hash + 'static, 140 | V: 'static, 141 | { 142 | /// Creates a new `ShardMap` with the provided hasher `S`. 143 | pub fn with_hasher(hasher: S) -> Self { 144 | Self::with_shards_and_hasher(shard_count(), hasher) 145 | } 146 | 147 | /// Creates a new `ShardMap` with the provided hasher `S` and space for at least `cap` elements. 148 | pub fn with_capacity_and_hasher(cap: usize, hasher: S) -> Self { 149 | Self::with_shards_and_capacity_and_hasher(shard_count(), cap, hasher) 150 | } 151 | 152 | /// Creates a new `ShardMap` with the provided hasher `S` and `shards` shards. 153 | pub fn with_shards_and_hasher(shards: usize, hasher: S) -> Self { 154 | Self::with_shards_and_capacity_and_hasher(shards, 4, hasher) 155 | } 156 | 157 | /// Creates a new `ShardMap` with the provided hasher `S`, `shards` shards, and space for at 158 | /// least `cap` elements. 159 | pub fn with_shards_and_capacity_and_hasher(shards: usize, mut cap: usize, hasher: S) -> Self { 160 | debug_assert!(shards > 1); 161 | debug_assert!(shards.is_power_of_two()); 162 | 163 | let shift = ptr_size_bits() - (shards.trailing_zeros() as usize); 164 | 165 | if cap != 0 { 166 | cap = (cap + (shards - 1)) & !(shards - 1); 167 | } 168 | let shard_capacity = cap / shards; 169 | 170 | let shards = std::iter::repeat(()) 171 | .take(shards) 172 | .map(|_| CachePadded::new(Shard::with_capacity(shard_capacity))) 173 | .collect(); 174 | 175 | Self { 176 | inner: Arc::new(Inner { 177 | shards, 178 | shift, 179 | hasher, 180 | }), 181 | } 182 | } 183 | 184 | #[inline] 185 | fn shard_for_hash(&self, hash: usize) -> usize { 186 | // 7 high bits for the HashBrown simd tag 187 | (hash << 7) >> self.inner.shift 188 | } 189 | 190 | #[inline] 191 | fn shard(&self, key: &K) -> (&CachePadded>, u64) { 192 | let hash = self.inner.hasher.hash_one(key); 193 | 194 | let shard_idx = self.shard_for_hash(hash as usize); 195 | 196 | (unsafe { self.inner.shards.get_unchecked(shard_idx) }, hash) 197 | } 198 | 199 | /// Inserts a key-value pair into the map. If the key already exists, the value is updated and 200 | /// the old value is returned. 201 | /// 202 | /// # Example 203 | /// ``` 204 | /// use tokio::runtime::Runtime; 205 | /// use std::sync::Arc; 206 | /// use whirlwind::ShardMap; 207 | /// let rt = Runtime::new().unwrap(); 208 | /// let map = Arc::new(ShardMap::new()); 209 | /// rt.block_on(async { 210 | /// map.insert("foo", "bar").await; 211 | /// 212 | /// assert_eq!(map.get(&"foo").await.unwrap().value(), &"bar"); 213 | /// }); 214 | /// ``` 215 | pub async fn insert(&self, key: K, value: V) -> Option { 216 | let (shard, hash) = self.shard(&key); 217 | let mut writer = shard.write().await; 218 | 219 | let (old, slot) = match writer.entry( 220 | hash, 221 | |(k, _)| k == &key, 222 | |(k, _)| self.inner.hasher.hash_one(k), 223 | ) { 224 | Entry::Occupied(entry) => { 225 | let ((_, old), slot) = entry.remove(); 226 | (Some(old), slot) 227 | } 228 | Entry::Vacant(slot) => (None, slot), 229 | }; 230 | 231 | slot.insert((key, value)); 232 | 233 | old 234 | } 235 | 236 | /// Returns a reference to the value associated with the key. 237 | /// If the key is not in the map, `None` is returned. 238 | /// 239 | /// # Example 240 | /// ``` 241 | /// use tokio::runtime::Runtime; 242 | /// use std::sync::Arc; 243 | /// use whirlwind::{ShardMap, mapref::MapRef}; 244 | /// 245 | /// let rt = Runtime::new().unwrap(); 246 | /// let map = Arc::new(ShardMap::new()); 247 | /// 248 | /// rt.block_on(async { 249 | /// map.insert("foo", "bar").await; 250 | /// 251 | /// // `get` returns a `MapRef` which holds a read lock on the shard. 252 | /// let entry: MapRef<'_, _, _> = map.get(&"foo").await.unwrap(); 253 | /// 254 | /// assert_eq!(entry.value(), &"bar"); 255 | /// }); 256 | /// ``` 257 | pub async fn get<'a>(&'a self, key: &'a K) -> Option> { 258 | let (shard, hash) = self.shard(key); 259 | let reader = shard.read().await; 260 | 261 | if let Some((k, v)) = reader.find(hash, |(k, _)| k == key) { 262 | let (k, v) = (k as *const K, v as *const V); 263 | // SAFETY: The key and value are guaranteed to be valid for the lifetime of the reader. 264 | unsafe { Some(MapRef::new(reader, &*k, &*v)) } 265 | } else { 266 | None 267 | } 268 | } 269 | 270 | /// Returns a mutable reference to the value associated with the key. 271 | /// If the key is not in the map, `None` is returned. 272 | /// 273 | /// # Example 274 | /// ``` 275 | /// use tokio::runtime::Runtime; 276 | /// use std::sync::Arc; 277 | /// use whirlwind::{ShardMap, mapref::MapRefMut}; 278 | /// 279 | /// let rt = Runtime::new().unwrap(); 280 | /// let map = Arc::new(ShardMap::new()); 281 | /// 282 | /// rt.block_on(async { 283 | /// map.insert("foo", "bar").await; 284 | /// 285 | /// // `get_mut` returns a `MapRefMut` which holds a write lock on the shard. 286 | /// let mut entry: MapRefMut<'_, _, _> = map.get_mut(&"foo").await.unwrap(); 287 | /// *entry.value_mut() = "baz"; 288 | /// 289 | /// assert_eq!(entry.value(), &"baz"); 290 | /// drop(entry); 291 | /// 292 | /// assert_eq!(map.get(&"foo").await.unwrap().value(), &"baz"); 293 | /// }); 294 | /// ``` 295 | pub async fn get_mut<'a>(&'a self, key: &'a K) -> Option> { 296 | let (shard, hash) = self.shard(key); 297 | let mut writer = shard.write().await; 298 | 299 | if let Some((k, v)) = writer.find_mut(hash, |(k, _)| k == key) { 300 | let (k, v) = (k as *const K, v as *mut V); 301 | // SAFETY: The key and value are guaranteed to be valid for the lifetime of the writer. 302 | unsafe { Some(MapRefMut::new(writer, &*k, &mut *v)) } 303 | } else { 304 | None 305 | } 306 | } 307 | 308 | /// Returns `true` if the map contains the key. 309 | /// 310 | /// # Example 311 | /// ``` 312 | /// use tokio::runtime::Runtime; 313 | /// use std::sync::Arc; 314 | /// use whirlwind::ShardMap; 315 | /// 316 | /// let rt = Runtime::new().unwrap(); 317 | /// let map = Arc::new(ShardMap::new()); 318 | /// 319 | /// rt.block_on(async { 320 | /// map.insert("foo", "bar").await; 321 | /// 322 | /// assert_eq!(map.contains_key(&"foo").await, true); 323 | /// 324 | /// assert_eq!(map.contains_key(&"bar").await, false); 325 | /// }); 326 | /// ``` 327 | pub async fn contains_key(&self, key: &K) -> bool { 328 | let (shard, hash) = self.shard(key); 329 | 330 | let reader = shard.read().await; 331 | 332 | reader.find(hash, |(k, _)| k == key).is_some() 333 | } 334 | 335 | /// Removes a key from the map and returns the value associated with the key. 336 | /// If the key is not in the map, `None` is returned. 337 | /// 338 | /// # Example 339 | /// ``` 340 | /// use tokio::runtime::Runtime; 341 | /// use std::sync::Arc; 342 | /// use whirlwind::ShardMap; 343 | /// 344 | /// let rt = Runtime::new().unwrap(); 345 | /// let map = Arc::new(ShardMap::new()); 346 | /// 347 | /// rt.block_on(async { 348 | /// map.insert("foo", "bar").await; 349 | /// 350 | /// assert_eq!(map.contains_key(&"foo").await, true); 351 | /// 352 | /// let value = map.remove(&"foo").await; 353 | /// 354 | /// assert_eq!(value, Some("bar")); 355 | /// 356 | /// assert_eq!(map.contains_key(&"foo").await, false); 357 | /// }); 358 | /// ``` 359 | pub async fn remove(&self, key: &K) -> Option { 360 | let (shard, hash) = self.shard(key); 361 | 362 | match shard.write().await.find_entry(hash, |(k, _)| k == key) { 363 | Ok(occupied) => { 364 | let ((_, v), _) = occupied.remove(); 365 | Some(v) 366 | } 367 | _ => None, 368 | } 369 | } 370 | 371 | /// Returns the number of elements in the map. 372 | /// 373 | /// # Example 374 | /// ``` 375 | /// use tokio::runtime::Runtime; 376 | /// use std::sync::Arc; 377 | /// use whirlwind::ShardMap; 378 | /// 379 | /// let rt = Runtime::new().unwrap(); 380 | /// let map = Arc::new(ShardMap::new()); 381 | /// 382 | /// rt.block_on(async { 383 | /// map.insert("foo", "bar").await; 384 | /// assert_eq!(map.len().await, 1); 385 | /// map.insert("foo2", "bar2").await; 386 | /// assert_eq!(map.len().await, 2); 387 | /// }); 388 | /// ``` 389 | pub async fn len(&self) -> usize { 390 | let mut sum = 0; 391 | for shard in self.inner.iter() { 392 | sum += shard.read().await.len(); 393 | } 394 | sum 395 | } 396 | 397 | /// Returns `true` if the map is empty. 398 | /// 399 | /// This is equivalent to `map.len().await == 0`. 400 | /// 401 | /// # Example 402 | /// ``` 403 | /// use tokio::runtime::Runtime; 404 | /// use std::sync::Arc; 405 | /// use whirlwind::ShardMap; 406 | /// 407 | /// let rt = Runtime::new().unwrap(); 408 | /// let map = Arc::new(ShardMap::new()); 409 | /// rt.block_on(async { 410 | /// assert_eq!(map.is_empty().await, true); 411 | /// 412 | /// map.insert("foo", "bar").await; 413 | /// assert_eq!(map.is_empty().await, false); 414 | /// 415 | /// map.remove(&"foo").await; 416 | /// assert_eq!(map.is_empty().await, true); 417 | /// }); 418 | /// 419 | /// ``` 420 | pub async fn is_empty(&self) -> bool { 421 | self.len().await == 0 422 | } 423 | 424 | /// Clears the map, removing all key-value pairs. 425 | /// 426 | /// # Example 427 | /// 428 | /// ``` 429 | /// use tokio::runtime::Runtime; 430 | /// use std::sync::Arc; 431 | /// use whirlwind::ShardMap; 432 | /// 433 | /// let rt = Runtime::new().unwrap(); 434 | /// let map = Arc::new(ShardMap::new()); 435 | /// 436 | /// rt.block_on(async { 437 | /// map.insert("foo", "bar").await; 438 | /// map.insert("baz", "qux").await; 439 | /// 440 | /// assert_eq!(map.len().await, 2); 441 | /// 442 | /// map.clear().await; 443 | /// 444 | /// assert_eq!(map.is_empty().await, true); 445 | /// }); 446 | pub async fn clear(&self) { 447 | for shard in self.inner.iter() { 448 | shard.write().await.clear(); 449 | } 450 | } 451 | } 452 | -------------------------------------------------------------------------------- /src/shard_set.rs: -------------------------------------------------------------------------------- 1 | //! # ShardSet 2 | //! 3 | //! A concurrent set based on a [`ShardMap`] with values of `()`. 4 | //! 5 | //! # Example 6 | //! 7 | //! ``` 8 | //! use std::sync::Arc; 9 | //! use whirlwind::ShardSet; 10 | //! 11 | //! let rt = tokio::runtime::Runtime::new().unwrap(); 12 | //! let set = Arc::new(ShardSet::new()); 13 | //! 14 | //! rt.block_on(async { 15 | //! for i in 0..10 { 16 | //! let k = i; 17 | //! if i % 2 == 0 { 18 | //! set.insert(k).await; 19 | //! } else { 20 | //! set.remove(&(k-1)).await; 21 | //! } 22 | //! } 23 | //! }); 24 | //! ``` 25 | //! 26 | use std::hash::{BuildHasher, Hash, RandomState}; 27 | 28 | use crate::shard_map::ShardMap; 29 | 30 | /// A concurrent set based on a [`ShardMap`] with values of `()`. 31 | /// 32 | /// # Example 33 | /// 34 | /// ``` 35 | /// use std::sync::Arc; 36 | /// use whirlwind::ShardSet; 37 | /// 38 | /// let rt = tokio::runtime::Runtime::new().unwrap(); 39 | /// let set = Arc::new(ShardSet::new()); 40 | /// 41 | /// rt.block_on(async { 42 | /// for i in 0..10 { 43 | /// let k = i; 44 | /// if i % 2 == 0 { 45 | /// set.insert(k).await; 46 | /// } else { 47 | /// set.remove(&(k-1)).await; 48 | /// } 49 | /// } 50 | /// }); 51 | /// ``` 52 | /// 53 | pub struct ShardSet { 54 | inner: ShardMap, 55 | } 56 | 57 | impl Default for ShardSet { 58 | fn default() -> Self { 59 | Self::new() 60 | } 61 | } 62 | 63 | impl ShardSet { 64 | pub fn new() -> Self { 65 | Self { 66 | inner: ShardMap::new(), 67 | } 68 | } 69 | 70 | pub fn new_with_shards(shards: usize) -> Self { 71 | Self { 72 | inner: ShardMap::with_shards(shards), 73 | } 74 | } 75 | } 76 | 77 | impl ShardSet 78 | where 79 | T: Eq + std::hash::Hash + 'static, 80 | S: BuildHasher, 81 | { 82 | pub fn new_with_hasher(hasher: S) -> Self { 83 | Self { 84 | inner: ShardMap::with_hasher(hasher), 85 | } 86 | } 87 | 88 | pub fn new_with_shards_and_hasher(shards: usize, hasher: S) -> Self { 89 | Self { 90 | inner: ShardMap::with_shards_and_hasher(shards, hasher), 91 | } 92 | } 93 | 94 | /// Inserts a value into the set. 95 | pub async fn insert(&self, value: T) { 96 | self.inner.insert(value, ()).await; 97 | } 98 | 99 | /// Returns `true` if the set contains the specified value. 100 | pub async fn contains(&self, value: &T) -> bool { 101 | self.inner.contains_key(value).await 102 | } 103 | 104 | /// Removes a value from the set. 105 | pub async fn remove(&self, value: &T) -> bool { 106 | self.inner.remove(value).await.is_some() 107 | } 108 | 109 | /// Returns the number of elements in the set. 110 | pub async fn len(&self) -> usize { 111 | self.inner.len().await 112 | } 113 | 114 | /// Returns `true` if the set is empty. 115 | pub async fn is_empty(&self) -> bool { 116 | self.inner.len().await == 0 117 | } 118 | 119 | /// Clears the set, removing all values. 120 | pub async fn clear(&self) { 121 | self.inner.clear().await; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /tests/basic.rs: -------------------------------------------------------------------------------- 1 | use whirlwind::*; 2 | 3 | #[tokio::test] 4 | async fn test_shardmap() { 5 | let map = ShardMap::new(); 6 | map.insert("foo", "bar").await; 7 | assert_eq!(map.len().await, 1); 8 | assert_eq!(map.contains_key(&"foo").await, true); 9 | assert_eq!(map.contains_key(&"bar").await, false); 10 | assert_eq!(map.get(&"foo").await.unwrap().value(), &"bar"); 11 | assert!(map.get(&"bar").await.is_none()); 12 | assert_eq!(map.remove(&"foo").await, Some("bar")); 13 | assert_eq!(map.len().await, 0); 14 | assert_eq!(map.contains_key(&"foo").await, false); 15 | } 16 | 17 | #[tokio::test] 18 | async fn test_shardmap_clone() { 19 | let map = ShardMap::new(); 20 | map.insert("foo", "bar").await; 21 | let map2 = map.clone(); 22 | assert_eq!(map2.len().await, 1); 23 | assert_eq!(map2.contains_key(&"foo").await, true); 24 | assert_eq!(map2.contains_key(&"bar").await, false); 25 | assert_eq!(map2.get(&"foo").await.unwrap().value(), &"bar"); 26 | assert!(map2.get(&"bar").await.is_none()); 27 | assert_eq!(map2.remove(&"foo").await, Some("bar")); 28 | assert_eq!(map2.len().await, 0); 29 | assert_eq!(map2.contains_key(&"foo").await, false); 30 | } 31 | 32 | #[tokio::test] 33 | async fn test_shardmap_shards() { 34 | let map = ShardMap::with_shards(4); 35 | map.insert("foo", "bar").await; 36 | assert_eq!(map.len().await, 1); 37 | assert_eq!(map.contains_key(&"foo").await, true); 38 | assert_eq!(map.contains_key(&"bar").await, false); 39 | assert_eq!(map.get(&"foo").await.unwrap().value(), &"bar"); 40 | assert!(map.get(&"bar").await.is_none()); 41 | assert_eq!(map.remove(&"foo").await, Some("bar")); 42 | assert_eq!(map.len().await, 0); 43 | assert_eq!(map.contains_key(&"foo").await, false); 44 | } 45 | 46 | #[tokio::test] 47 | async fn test_shardmap_len() { 48 | let map = ShardMap::new(); 49 | map.insert("foo", "bar").await; 50 | assert_eq!(map.len().await, 1); 51 | map.insert("foo2", "bar2").await; 52 | assert_eq!(map.len().await, 2); 53 | map.remove(&"foo").await; 54 | assert_eq!(map.len().await, 1); 55 | map.remove(&"foo2").await; 56 | assert_eq!(map.len().await, 0); 57 | } 58 | 59 | #[tokio::test] 60 | async fn test_shardmap_is_empty() { 61 | let map = ShardMap::new(); 62 | assert_eq!(map.is_empty().await, true); 63 | map.insert("foo", "bar").await; 64 | assert_eq!(map.is_empty().await, false); 65 | map.remove(&"foo").await; 66 | assert_eq!(map.is_empty().await, true); 67 | } 68 | --------------------------------------------------------------------------------