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

Use tries for IDL variant-of-struct lookups

    • Type: Icon: Task Task
    • Resolution: Fixed
    • Priority: Icon: Major - P3 Major - P3
    • 8.0.0-rc0
    • Affects Version/s: None
    • Component/s: None
    • Service Arch
    • Fully Compatible
    • Repl 2023-12-25, Repl 2024-01-08, Repl 2024-01-22, Service Arch 2024-02-05

      Currently we don't, but it's pretty easy to get it to use it by calling gen_trie. This should speed up parsing by about 5 - 10% (this is what I saw in a microbenchmark).

      When parsing a variant of several structs (std::variant<Struct1, ...>), instead of using a trie or some other smarter method we match each field name and try to figure out which struct to construct. This is what currently generated code looks like. Note how the field name is matched against "struct1", "struct2" and "struct3" even though the string "struct" is common between all three cases.

      std::variant<mongo::Struct1, mongo::Struct2, mongo::Struct3> _tmp;
      
      const BSONType variantType = arrayElement.type();
      switch (variantType) {
      case Object:
          {
              auto firstElement = arrayElement.Obj().firstElement();
              if (firstElement.fieldNameStringData() == "struct1") {
                  _tmp = mongo::Struct1::parse(ctxt, arrayElement.Obj());
              } else if (firstElement.fieldNameStringData() == "struct2") {
                  _tmp = mongo::Struct2::parse(ctxt, arrayElement.Obj());
              } else if (firstElement.fieldNameStringData() == "struct3") {
                  _tmp = mongo::Struct3::parse(ctxt, arrayElement.Obj());
              } else {
                  ctxt.throwUnknownField(firstElement.fieldNameStringData());
              }
              break;
          }
      default:
          ctxt.throwBadType(arrayElement, std::array<BSONType, 0>{});
          break;
      }
      

            Assignee:
            billy.donahue@mongodb.com Billy Donahue
            Reporter:
            vishnu.kaushik@mongodb.com Vishnu Kaushik
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved: