Skip to content

dicts: improve performance for non-concrete values and keys#971

Merged
KristofferC merged 1 commit into
JuliaCollections:masterfrom
KristofferC:kc/non_concrete
Jun 1, 2026
Merged

dicts: improve performance for non-concrete values and keys#971
KristofferC merged 1 commit into
JuliaCollections:masterfrom
KristofferC:kc/non_concrete

Conversation

@KristofferC
Copy link
Copy Markdown
Collaborator

@KristofferC KristofferC commented Jun 1, 2026

Same as JuliaCollections/OrderedCollections.jl#166

Benchmark:

  using DataStructures
  using BenchmarkTools

  const N = 1000
  pairs = [i => (iseven(i) ? i : Float64(i)) for i in 1:N]

  d_base  = Dict{Int,Number}(pairs)
  d_robin = RobinDict{Int,Number}(pairs)
  d_ord   = OrderedRobinDict{Int,Number}(pairs)
  d_swiss = SwissDict{Int,Number}(pairs)

  function sumvals(d)
      s = 0.0
      for (k, v) in d
          s += v
      end
      return s
  end

  print("Dict (base):       "); @btime sumvals($d_base)
  print("RobinDict:         "); @btime sumvals($d_robin)
  print("OrderedRobinDict:  "); @btime sumvals($d_ord)
  print("SwissDict:         "); @btime sumvals($d_swiss)

Results:

  Dict (base):         15.870 μs (1000 allocations: 15.62 KiB)

  Before
  OrderedRobinDict:    145.245 μs (3234 allocations: 66.16 KiB)
  SwissDict:           142.385 μs (3234 allocations: 66.16 KiB)

  After
  OrderedRobinDict:    13.913 μs (1000 allocations: 15.62 KiB)
  SwissDict:           13.795 μs (1000 allocations: 15.62 KiB)

@KristofferC KristofferC merged commit c1fb53c into JuliaCollections:master Jun 1, 2026
12 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants