-
Type: Task
-
Resolution: Fixed
-
Priority: Major - P3
-
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; }
- depends on
-
SERVER-85497 IDL: make gen_trie generate a complete lookup function
- Closed