MCPcopy Index your code
hub / github.com/cockroachdb/swiss

github.com/cockroachdb/swiss @main

Chat with this repo
repository ↗ · DeepWiki ↗ · + Follow
139 symbols 496 edges 9 files 70 documented · 50% 10 cross-repo links
What it actually does AI analysis from the code graph — generated when you open this
loading…
README

Swiss Map Build Status GoDoc

swiss.Map is a Go implementation of Google's Swiss Tables hash table design. The Rust version of Swiss Tables is now the HashMap implementation in the Rust standard library.

A swiss.Map[K,V] maps keys of type K to values of type V, similar to Go's builtin map[K]V type. The primary advantage of swiss.Map over Go's builtin map is performance. swiss.Map has similar or slightly better performance than Go's builtin map for small map sizes, and significantly better performance at large map sizes. The benchmarks where swiss.Map performs worse are due to a fast-path optimization in Go's builtin maps for tiny (6 or fewer element) maps with int32, int64, or string keys, and when growing a tiny map no initial capacity specified. In the latter case, Go's builtin map is sometimes able to place the map and first bucket on the stack avoiding heap allocations entirely.

Performance: Go's builtin map (old) vs swiss.Map (new)

Tested on a GCE n1-standard-16 instance.

``` goos: linux goarch: amd64 pkg: github.com/cockroachdb/swiss cpu: Intel(R) Xeon(R) CPU @ 2.60GHz

name old time/op new time/op delta MapIter/Int/6-16 72.9ns ± 1% 38.3ns ± 1% -47.53% (p=0.000 n=10+10) MapIter/Int/12-16 123ns ± 1% 56ns ± 2% -54.72% (p=0.000 n=9+10) MapIter/Int/18-16 191ns ± 5% 80ns ± 1% -58.11% (p=0.000 n=10+9) MapIter/Int/24-16 229ns ± 4% 89ns ± 1% -61.41% (p=0.000 n=10+10) MapIter/Int/30-16 300ns ± 2% 125ns ± 2% -58.47% (p=0.000 n=9+10) MapIter/Int/64-16 588ns ± 3% 233ns ± 1% -60.33% (p=0.000 n=10+10) MapIter/Int/128-16 1.14µs ± 4% 0.45µs ± 1% -60.73% (p=0.000 n=10+10) MapIter/Int/256-16 2.38µs ± 2% 0.86µs ± 0% -63.89% (p=0.000 n=10+10) MapIter/Int/512-16 5.13µs ± 2% 1.70µs ± 0% -66.89% (p=0.000 n=10+10) MapIter/Int/1024-16 11.0µs ± 2% 4.0µs ± 3% -63.31% (p=0.000 n=10+10) MapIter/Int/2048-16 22.6µs ± 2% 10.7µs ± 1% -52.70% (p=0.000 n=10+9) MapIter/Int/4096-16 45.8µs ± 2% 23.6µs ± 0% -48.52% (p=0.000 n=10+10) MapIter/Int/8192-16 91.4µs ± 0% 48.7µs ± 0% -46.67% (p=0.000 n=8+9) MapIter/Int/32768-16 367µs ± 1% 198µs ± 0% -46.03% (p=0.000 n=10+10) MapIter/Int/65536-16 735µs ± 1% 397µs ± 0% -46.03% (p=0.000 n=10+10) MapIter/Int/131072-16 1.47ms ± 1% 0.79ms ± 0% -46.01% (p=0.000 n=9+10) MapIter/Int/262144-16 2.96ms ± 2% 1.60ms ± 0% -46.04% (p=0.000 n=10+10) MapIter/Int/524288-16 6.07ms ± 2% 3.23ms ± 0% -46.82% (p=0.000 n=10+10) MapIter/Int/1048576-16 12.3ms ± 2% 6.9ms ± 1% -44.18% (p=0.000 n=10+10) MapIter/Int/2097152-16 24.9ms ± 1% 14.5ms ± 1% -41.78% (p=0.000 n=10+10) MapIter/Int/4194304-16 50.5ms ± 1% 29.2ms ± 1% -42.14% (p=0.000 n=10+10) MapGetHit/Int64/6-16 4.93ns ± 0% 6.62ns ±15% +34.14% (p=0.000 n=10+10) MapGetHit/Int64/12-16 7.29ns ± 1% 6.35ns ± 0% -12.89% (p=0.000 n=8+8) MapGetHit/Int64/18-16 7.57ns ±18% 6.56ns ± 9% -13.30% (p=0.001 n=10+10) MapGetHit/Int64/24-16 7.54ns ± 5% 6.67ns ± 7% -11.56% (p=0.000 n=10+9) MapGetHit/Int64/30-16 7.01ns ± 2% 6.35ns ± 0% -9.46% (p=0.000 n=10+8) MapGetHit/Int64/64-16 7.09ns ± 1% 6.72ns ±10% -5.23% (p=0.001 n=10+10) MapGetHit/Int64/128-16 7.13ns ± 2% 6.73ns ± 3% -5.62% (p=0.000 n=10+10) MapGetHit/Int64/256-16 7.14ns ± 1% 6.72ns ± 3% -5.96% (p=0.000 n=10+10) MapGetHit/Int64/512-16 7.20ns ± 1% 6.76ns ± 1% -6.15% (p=0.000 n=10+9) MapGetHit/Int64/1024-16 7.44ns ± 1% 6.81ns ± 1% -8.41% (p=0.000 n=10+8) MapGetHit/Int64/2048-16 10.2ns ± 4% 7.1ns ± 1% -29.79% (p=0.000 n=10+10) MapGetHit/Int64/4096-16 16.4ns ± 2% 8.6ns ± 1% -47.76% (p=0.000 n=10+10) MapGetHit/Int64/8192-16 19.6ns ± 2% 8.9ns ± 1% -54.48% (p=0.000 n=10+10) MapGetHit/Int64/32768-16 23.0ns ± 1% 9.9ns ± 1% -57.18% (p=0.000 n=10+10) MapGetHit/Int64/65536-16 26.0ns ± 1% 14.1ns ± 3% -45.65% (p=0.000 n=10+10) MapGetHit/Int64/131072-16 27.1ns ± 1% 16.1ns ± 4% -40.67% (p=0.000 n=10+10) MapGetHit/Int64/262144-16 29.9ns ± 3% 17.7ns ± 4% -40.85% (p=0.000 n=10+10) MapGetHit/Int64/524288-16 33.5ns ± 5% 20.1ns ± 2% -39.88% (p=0.000 n=10+7) MapGetHit/Int64/1048576-16 45.3ns ±10% 30.8ns ± 9% -32.00% (p=0.000 n=10+10) MapGetHit/Int64/2097152-16 55.4ns ± 2% 47.0ns ± 3% -15.07% (p=0.000 n=10+10) MapGetHit/Int64/4194304-16 58.7ns ± 2% 55.0ns ± 2% -6.34% (p=0.000 n=9+10) MapGetHit/Int32/6-16 5.04ns ± 0% 6.40ns ± 0% +27.16% (p=0.000 n=10+9) MapGetHit/Int32/12-16 7.71ns ±11% 6.53ns ± 3% -15.29% (p=0.000 n=10+9) MapGetHit/Int32/18-16 8.04ns ± 8% 6.41ns ± 0% -20.29% (p=0.000 n=8+8) MapGetHit/Int32/24-16 7.93ns ±10% 6.61ns ± 6% -16.71% (p=0.000 n=10+10) MapGetHit/Int32/30-16 7.00ns ± 4% 6.74ns ±13% ~ (p=0.165 n=10+10) MapGetHit/Int32/64-16 7.05ns ± 0% 6.75ns ± 2% -4.20% (p=0.000 n=8+8) MapGetHit/Int32/128-16 7.08ns ± 1% 6.94ns ± 5% -2.06% (p=0.028 n=9+10) MapGetHit/Int32/256-16 7.11ns ± 1% 6.76ns ± 4% -4.90% (p=0.000 n=10+10) MapGetHit/Int32/512-16 7.22ns ± 1% 6.79ns ± 4% -5.99% (p=0.000 n=10+10) MapGetHit/Int32/1024-16 7.31ns ± 0% 6.72ns ± 1% -8.14% (p=0.000 n=8+10) MapGetHit/Int32/2048-16 8.91ns ± 6% 6.76ns ± 1% -24.15% (p=0.000 n=10+10) MapGetHit/Int32/4096-16 16.3ns ± 1% 8.1ns ± 1% -50.37% (p=0.000 n=9+10) MapGetHit/Int32/8192-16 19.1ns ± 1% 8.4ns ± 1% -55.92% (p=0.000 n=10+10) MapGetHit/Int32/32768-16 22.0ns ± 1% 8.9ns ± 0% -59.57% (p=0.000 n=10+8) MapGetHit/Int32/65536-16 24.0ns ± 0% 10.2ns ± 1% -57.39% (p=0.000 n=9+8) MapGetHit/Int32/131072-16 26.2ns ± 1% 13.5ns ± 4% -48.57% (p=0.000 n=10+10) MapGetHit/Int32/262144-16 27.1ns ± 1% 15.2ns ± 3% -43.76% (p=0.000 n=10+10) MapGetHit/Int32/524288-16 30.2ns ± 4% 16.4ns ± 3% -45.49% (p=0.000 n=9+10) MapGetHit/Int32/1048576-16 34.3ns ±10% 19.4ns ± 3% -43.58% (p=0.000 n=9+10) MapGetHit/Int32/2097152-16 44.4ns ±11% 29.5ns ± 5% -33.50% (p=0.000 n=10+10) MapGetHit/Int32/4194304-16 52.8ns ± 3% 42.7ns ± 2% -19.13% (p=0.000 n=9+10) MapGetHit/String/6-16 12.9ns ± 1% 9.7ns ±23% -24.32% (p=0.000 n=10+10) MapGetHit/String/12-16 9.52ns ± 7% 9.52ns ± 7% ~ (p=0.930 n=10+10) MapGetHit/String/18-16 10.4ns ± 5% 9.5ns ± 1% -8.91% (p=0.000 n=9+9) MapGetHit/String/24-16 9.67ns ± 9% 10.95ns ± 5% +13.17% (p=0.000 n=10+8) MapGetHit/String/30-16 8.74ns ± 3% 9.48ns ± 1% +8.49% (p=0.000 n=10+8) MapGetHit/String/64-16 8.94ns ± 2% 10.02ns ± 4% +12.02% (p=0.000 n=10+10) MapGetHit/String/128-16 9.47ns ± 2% 10.02ns ± 4% +5.82% (p=0.000 n=10+10) MapGetHit/String/256-16 10.3ns ± 2% 10.0ns ± 4% -3.33% (p=0.000 n=10+10) MapGetHit/String/512-16 10.9ns ± 2% 10.0ns ± 4% -7.78% (p=0.000 n=10+10) MapGetHit/String/1024-16 11.3ns ± 2% 10.5ns ± 5% -7.45% (p=0.000 n=9+10) MapGetHit/String/2048-16 15.7ns ± 6% 10.8ns ± 1% -31.48% (p=0.000 n=10+10) MapGetHit/String/4096-16 27.2ns ± 2% 12.6ns ± 1% -53.77% (p=0.000 n=10+10) MapGetHit/String/8192-16 30.1ns ± 1% 13.1ns ± 1% -56.64% (p=0.000 n=10+10) MapGetHit/String/32768-16 37.3ns ± 1% 19.3ns ± 2% -48.32% (p=0.000 n=10+9) MapGetHit/String/65536-16 39.0ns ± 1% 22.1ns ± 4% -43.25% (p=0.000 n=9+10) MapGetHit/String/131072-16 40.7ns ± 4% 25.0ns ± 3% -38.72% (p=0.000 n=10+10) MapGetHit/String/262144-16 52.7ns ± 7% 28.5ns ± 4% -45.97% (p=0.000 n=10+10) MapGetHit/String/524288-16 68.5ns ±10% 40.4ns ± 3% -41.06% (p=0.000 n=10+8) MapGetHit/String/1048576-16 76.8ns ± 4% 64.1ns ± 7% -16.46% (p=0.000 n=10+10) MapGetHit/String/2097152-16 86.5ns ± 2% 78.7ns ± 1% -9.00% (p=0.000 n=10+9) MapGetHit/String/4194304-16 94.4ns ± 5% 86.7ns ± 1% -8.23% (p=0.000 n=10+10) MapGetMiss/Int64/6-16 7.16ns ± 0% 7.49ns ± 0% +4.62% (p=0.000 n=10+8) MapGetMiss/Int64/12-16 11.1ns ±37% 8.9ns ±17% -19.60% (p=0.000 n=10+10) MapGetMiss/Int64/18-16 10.0ns ± 0% 8.2ns ±18% -17.55% (p=0.000 n=8+10) MapGetMiss/Int64/24-16 11.5ns ±14% 9.7ns ±16% -15.75% (p=0.002 n=10+10) MapGetMiss/Int64/30-16 9.94ns ± 0% 7.88ns ± 5% -20.79% (p=0.000 n=9+10) MapGetMiss/Int64/64-16 11.4ns ±16% 8.2ns ± 4% -28.39% (p=0.000 n=10+10) MapGetMiss/Int64/128-16 10.5ns ± 8% 8.4ns ± 4% -19.95% (p=0.000 n=10+10) MapGetMiss/Int64/256-16 10.5ns ± 5% 8.5ns ± 6% -18.62% (p=0.000 n=10+10) MapGetMiss/Int64/512-16 10.3ns ± 2% 8.6ns ± 5% -16.34% (p=0.000 n=8+10) MapGetMiss/Int64/1024-16 10.5ns ± 3% 8.7ns ± 2% -17.18% (p=0.000 n=10+10) MapGetMiss/Int64/2048-16 10.9ns ± 2% 8.9ns ± 2% -17.72% (p=0.000 n=10+10) MapGetMiss/Int64/4096-16 11.1ns ± 1% 10.5ns ± 2% -5.45% (p=0.000 n=8+10) MapGetMiss/Int64/8192-16 11.7ns ± 2% 10.9ns ± 1% -6.53% (p=0.000 n=10+10) MapGetMiss/Int64/32768-16 14.0ns ± 1% 11.6ns ± 1% -17.32% (p=0.000 n=10+10) MapGetMiss/Int64/65536-16 17.2ns ± 1% 12.6ns ± 1% -26.46% (p=0.000 n=9+10) MapGetMiss/Int64/131072-16 18.4ns ± 3% 14.5ns ± 2% -21.17% (p=0.000 n=10+10) MapGetMiss/Int64/262144-16 20.1ns ± 2% 16.1ns ± 3% -19.93% (p=0.000 n=8+10) MapGetMiss/Int64/524288-16 42.3ns ±28% 18.0ns ± 3% -57.35% (p=0.000 n=10+10) MapGetMiss/Int64/1048576-16 53.3ns ± 7% 21.7ns ± 5% -59.34% (p=0.000 n=8+10) MapGetMiss/Int64/2097152-16 58.5ns ± 4% 32.9ns ± 5% -43.80% (p=0.000 n=10+10) MapGetMiss/Int64/4194304-16 63.2ns ± 7% 43.5ns ± 3% -31.16% (p=0.000 n=9+10) MapGetMiss/Int32/6-16 8.92ns ± 0% 7.19ns ± 0% -19.45% (p=0.000 n=10+8) MapGetMiss/Int32/12-16 11.0ns ± 0% 8.7ns ±18% -20.45% (p=0.000 n=9+10) MapGetMiss/Int32/18-16 11.0ns ± 0% 7.6ns ±10% -31.26% (p=0.000 n=9+10) MapGetMiss/Int32/24-16 12.5ns ±15% 9.1ns ±22% -27.69% (p=0.000 n=10+10) MapGetMiss/Int32/30-16 11.0ns ± 0% 7.7ns ± 6% -30.29% (p=0.000 n=8+10) MapGetMiss/Int32/64-16 11.0ns ± 0% 7.8ns ± 7% -28.75% (p=0.000 n=9+9) MapGetMiss/Int32/128-16 11.7ns ±13% 8.0ns ± 6% -31.76% (p=0.000 n=10+10) MapGetMiss/Int32/256-16 11.5ns ± 4% 8.2ns ± 6% -28.83% (p=0.000 n=10+10) MapGetMiss/Int32/512-16 11.4ns ± 6% 8.3ns ± 1% -26.91% (p=0.000 n=10+8) MapGetMiss/Int32/1024-16 11.5ns ± 3% 8.4ns ± 3% -26.83% (p=0.000 n=10+10) MapGetMiss/Int32/2048-16 11.5ns ± 2% 8.5ns ± 3% -25.93% (p=0.000 n=9+10) MapGetMiss/Int32/4096-16 11.5ns ± 1% 10.1ns ± 2% -12.27% (p=0.000 n=10+10) MapGetMiss/Int32/8192-16 11.6ns ± 2% 10.3ns ± 0% -11.61% (p=0.000 n=10+8) MapGetMiss/Int32/32768-16 12.5ns ± 1% 11.0ns ± 1% -11.58% (p=0.000 n=10+10) MapGetMiss/Int32/65536-16 14.2ns ± 2% 11.8ns ± 1% -16.82% (p=0.000 n=9+10) MapGetMiss/Int32/131072-16 17.1ns ± 2% 14.3ns ± 2% -16.72% (p=0.000 n=10+10) MapGetMiss/Int32/262144-16 18.1ns ± 3% 15.3ns ± 3% -15.47% (p=0.000 n=9+10) MapGetMiss/Int32/524288-16 20.9ns ± 7% 16.8ns ± 2% -19.84% (p=0.000 n=10+10) MapGetMiss/Int32/1048576-16 24.9ns ±16% 20.1ns ± 3% -19.08% (p=0.000 n=9+9) MapGetMiss/Int32/2097152-16 38.6ns ±20% 32.3ns ± 9% -16.22% (p=0.003 n=10+10) MapGetMiss/Int32/4194304-16 51.6ns ± 6% 42.9ns ± 3% -16.85% (p=0.000 n=10+10) MapGetMiss/String/6-16 7.79ns ± 0% 9.77ns ± 9% +25.41% (p=0.000 n=10+10) MapGetMiss/String/12-16

Extension points exported contracts — how you extend this code

Option (Interface)
Option provides an interface for passing configuration parameters for Map initialization.
options.go
Allocator (Interface)
Allocator specifies an interface for allocating and releasing memory used by a Map. The default allocator utilizes Go's
options.go

Core symbols most depended-on inside this repo

At
called by 57
map.go
Put
called by 22
map.go
Get
called by 19
map.go
globalDepth
called by 14
map.go
checkInvariants
called by 14
map.go
Len
called by 12
map.go
Set
called by 11
endian_big.go
first
called by 10
map.go

Shape

Method 59
Function 54
Struct 16
TypeAlias 6
Interface 3
FuncType 1

Languages

Go100%

Modules by API surface

map.go66 symbols
bench_test.go24 symbols
map_test.go21 symbols
options.go15 symbols
runtime_go1.20.go9 symbols
endian_little.go2 symbols
endian_big.go2 symbols

For agents

$ claude mcp add swiss \
  -- python -m otcore.mcp_server <graph>

⬇ download graph artifact