-
Type: Improvement
-
Resolution: Done
-
Priority: Minor - P4
-
Affects Version/s: None
-
Component/s: Connections
-
None
-
Fully Compatible
Queue uses Array#delete_at(0) and Array#push to manage the connection pool. Array#pop and Array#unshift are substantially faster while maintaining FIFO semantics.
require 'benchmark/ips' arr = (1..100).to_a Benchmark.ips do |x| x.report("Stack") { arr.push arr.pop } x.report("Tail -> Head Queue") { arr.unshift arr.pop } x.report("Head -> Tail Queue (shift)") { arr.push arr.shift } x.report("Head -> Tail Queue (delete_at)") { arr.push arr.delete_at(0) } end Stack 4.994M (± 0.2%) i/s - 24.985M Tail -> Head Queue 5.092M (± 0.1%) i/s - 25.521M Head -> Tail Queue (shift) 4.898M (± 0.1%) i/s - 24.511M Head -> Tail Queue (delete_at) 4.453M (± 0.1%) i/s - 22.289M
My fix is here:
https://github.com/cheald/mongo-ruby-driver/commit/a8cafb7f5a30ec22334a23b166efba9f01618580