[SERVER-83513] Use tries for IDL variant-of-struct lookups Created: 21/Nov/23  Updated: 04/Feb/24  Resolved: 04/Feb/24

Status: Closed
Project: Core Server
Component/s: None
Affects Version/s: None
Fix Version/s: 8.0.0-rc0

Type: Task Priority: Major - P3
Reporter: Vishnu Kaushik Assignee: Billy Donahue
Resolution: Fixed Votes: 0
Labels: milestone-1
Remaining Estimate: Not Specified
Time Spent: Not Specified
Original Estimate: Not Specified

Issue Links:
Depends
depends on SERVER-85497 IDL: make gen_trie generate a complet... Closed
Assigned Teams:
Service Arch
Backwards Compatibility: Fully Compatible
Sprint: Repl 2023-12-25, Repl 2024-01-08, Repl 2024-01-22, Service Arch 2024-02-05
Participants:

 Description   

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;
}



 Comments   
Comment by Githook User [ 02/Feb/24 ]

Author:

{'name': 'Billy Donahue', 'email': 'billy.donahue@mongodb.com', 'username': 'BillyDonahue'}

Message: SERVER-83513 use trie to parse IDL variant-of-struct

GitOrigin-RevId: 3c2856b528157b71bd3a0e6a0e69daf966ac98b5
Branch: master
https://github.com/mongodb/mongo/commit/2d76a26618a0c9a156fd66b462139eda4fb30531

Generated at Thu Feb 08 06:52:24 UTC 2024 using Jira 9.7.1#970001-sha1:2222b88b221c4928ef0de3161136cc90c8356a66.