-
Type: Improvement
-
Resolution: Done
-
Priority: Major - P3
-
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.