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

Optimization opportunity in mongo::sbe::vm::ByteCode::runInternal()

    • Type: Icon: Improvement Improvement
    • Resolution: Unresolved
    • Priority: Icon: Major - P3 Major - P3
    • None
    • Affects Version/s: None
    • Component/s: None
    • None
    • Query Execution
    • 200
    • None
    • 3
    • TBD
    • None
    • None
    • None
    • None
    • None
    • None

      After switching to the toolchain v5 as default in 341832a we've observed few performance regressions including a 10% regression in ElemMatchLargeMixedInAndOrWithDuplicates causing BF-37502.

      The benchmark in question executes a simple find query with nested $elemMatch, $or, and $in predicates. Both $or and $in predicates have many arguments. The benchmark targets SBE engine (not yet enabled by default) which uses absl::raw_hash_set for $in predicate implementation.

      Our initial investigation identified >10% regressions in absl::raw_hash_set::find() (SERVER-104956) and in sbe::vm::ByteCode::runInternal() (this ticket). After disassembling sbe::vm::ByteCode::runInternal() we saw 25% more instructions in v4 binary which might indicate at more aggressive code in-lining. On the other hand, v4 contains 172 more branching instructions pointing at some other possible optimization (loop transforming?).

      The goal of this ticket is to identify relevant compile-time optimization in v4 vs. v5 toolchain for this particular workload and suggest or force it on sbe::vm::ByteCode::runInternal().

        1. bf-37502.js
          2 kB
        2. branching-address-comparison.png
          branching-address-comparison.png
          281 kB
        3. diff_flamegraph2.svg
          106 kB
        4. raw_hash_set_find_diff.svg
          488 kB
        5. run-internal-v4-asm.txt
          254 kB
        6. run-internal-v4-asm-annotated.txt
          314 kB
        7. run-internal-v5-asm.txt
          202 kB
        8. run-internal-v5-asm-annotated.txt
          253 kB

            Assignee:
            Unassigned Unassigned
            Reporter:
            romans.kasperovics@mongodb.com Romans Kasperovics
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated: