Uploaded image for project: 'Ruby Driver'
  1. Ruby Driver
  2. RUBY-1144

Performance regression compared to 1.x driver

    • Type: Icon: Improvement Improvement
    • Resolution: Done
    • Priority: Icon: Major - P3 Major - P3
    • bson-4.3.0
    • Affects Version/s: 2.3.0, bson-4.1.1
    • Component/s: BSON
    • Labels:
      None
    • Environment:
      ruby 2.3.1

      Hi,

      I'm looking at migrating some code that still uses 1.x of the driver to the current version. Unfortunately, I've hit a performance regression that is prohibitive for my use case - fetching large documents is about twice as slow.

      The difference seems to be largely down to the bson deserialisation. With the two attached (synthetic) benchmarks focussing on just that, the output I get is

      1.x driver

      serialize array old    659.130  (± 4.1%) i/s -   3.339k in   5.074290s
      serialize hash old     2.098k (± 3.4%) i/s -     10.556k in   5.038443s
      deserialize array old  7.027k (± 4.5%) i/s -     35.547k in   5.068561s
      deserialize hash old   442.631  (± 4.1%) i/s -   2.244k in   5.077907s
      

      Current driver

      serialize array new    438.138  (± 7.8%) i/s -      2.200k in   5.071809s
      serialize hash new     596.816  (± 5.0%) i/s -      3.016k in   5.067669s
      deserialize array new  496.616  (± 3.4%) i/s -      2.499k in   5.037972s
      deserialize hash new   246.083  (± 4.5%) i/s -      1.248k in   5.081219s
      

      I assume that a big chunk of the difference is down to 2.x being mostly in ruby with C implementation of some primitives (such as get_int32 etc) in C whereas in 1.x nearly the entire process is in the C extension (although it calls back into ruby land at various points). In addition, it looks like BSON::Registry.get is a bit of a hotspot

      Has any consideration been given to improving performance in this area? I'd be happy to spend some time looking at this, assuming patches are welcome & perhaps with some guidance as to desired approach.

        1. backported_bench.rb
          0.5 kB
        2. bson_bench_new.rb
          1 kB
        3. bson_bench.rb
          1.0 kB
        4. memory_bench.rb
          1 kB

            Assignee:
            emily.stolfo Emily Stolfo
            Reporter:
            fcheung Frederick Cheung
            Votes:
            1 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: