Uploaded image for project: 'Core Server'
  1. Core Server
  2. SERVER-67028

Fix 12% perf loss in validateBSON due to BSONElement changes

    • Type: Icon: Improvement Improvement
    • Resolution: Works as Designed
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None
    • Execution Team 2022-07-11

      The fix for SERVER-27209 removed a BSONElement constructor taking CachedSizeTag. However, while the constructor that we're using in its place allows specifying both the name length and the value length, it also allows replacing either argument by -1. This is suboptimal, as it requires checks for this magic value in the very hot path of constructing BSONElement values.

      The effect is a 12% drop in performance of validateBSON, as shown in the bson_bm benchmark regressing from 4.25GB/sec to 3.75 GB/sec. We should fix this either by reinstating the CachedSizeTag constructor, or (preferably, IMO) removing the special -1 uses for construction of elements. If we'd want these, using a special constructor for each of those would be reasonable. Call sites should always know whether they're defaulting either argument, so there really is no justification for much more fragile and slow run-time checks.

            Assignee:
            geert.bosch@mongodb.com Geert Bosch
            Reporter:
            geert.bosch@mongodb.com Geert Bosch
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: