|
Conclusions:
- Using mql specific setEquals builtin that performs checks, improves perf for 50-100 arg case by 73-126%, that results in reduction of regression from -40% to -10% in 100 arg case, and 10% improvement for 50arg case compared to classic.
- Using mql specific add builtin that performs checks, improves perf for 50-100 arg case by 132-357%, that results in improvement of regression from -43% to improvement of 157% for 100arg case compared to classic
- Using mql specific mul builtin that performs checks, improves perf for 10% for 50 arg case, but results in regression of -9% for 100 arg case. The 100arg case regression is explained by different overflow handling and promotion to Decimal. sbe currently builds balanced multiplication tree for 100+ args, which results in less decimal operations when compared to left-deep tree evaluation. The regression of -40% between sbe and classic is mostly explained by: 1) using decimal instead of double in case of overflow, 2) using interpreted checks rather than "builtin" checks.
Investigation branch:
https://github.com/10gen/mongo/compare/master...anna.wawrzyniak/SERVER-72644
All perf results:
https://docs.google.com/spreadsheets/d/1DQ8LprJYCt_DZxkhsnOtYoz-UOgKjPCagIvOArEt3Dc/edit#gid=0
|
|
After investigating setEquals variations, it looks like most of the degradation is because we add
if ((typeMatch(s4, 1088ll) ?: true) and if (!(isArray(s4)) || (!(isArray(s4)) || !(isArray(s5)))) \n then fail(7158100, \"All operands of $setEquals must be arrays.\")
|
to our generated expressions.
Moving those checks into a builtin function, like mqlSetEquals that performs those checks internally and then calls core setEquals, resulted in >70-120% perf improvement for >50 arguments, reversing most of the regression.
| |
master |
mqlSetEquals |
improvement |
| VariadicExpressionSetEqualsFifty.Crud.ftdc |
2731638466 |
1571666503 |
73.81% |
| VariadicExpressionSetEqualsFifty.VariadicAggExpressionSetEqualsFifty.ftdc |
2731460122 |
1571471998 |
73.82% |
| VariadicExpressionSetEqualsHundred.Crud.ftdc |
4281358874 |
1890906101 |
126.42% |
| VariadicExpressionSetEqualsHundred.VariadicAggExpressionSetEqualsHundred.ftdc |
4281147969 |
1890675577 |
126.43% |
| VariadicExpressionSetEqualsTen.Crud.ftdc |
1473774785 |
1268050867 |
16.22% |
| VariadicExpressionSetEqualsTen.VariadicAggExpressionSetEqualsTen.ftdc |
1473626448 |
1267878303 |
16.23% |
example query:
db.t2.aggregate([{$project: {setEquals: {$setEquals: ["$a", "$a", "$b"]}}}])
|
plan before:
[2] project [s8 = traverseP(s6, lambda(l1.0) { makeBsonObj(MakeObjSpec(keep, ["_id"], ["setEquals"]), l1.0,
|
if ((typeMatch(s4, 1088ll) ?: true) || ((typeMatch(s4, 1088ll) ?: true) || (typeMatch(s5, 1088ll) ?: true)))
|
then null
|
else
|
if (!(isArray(s4)) || (!(isArray(s4)) || !(isArray(s5))))
|
then fail(7158100, "All operands of $setEquals must be arrays.")
|
else setEquals(s4, s4, s5)
|
) }, Nothing)]
|
[1] scan s6 s7 none none none none [s4 = a, s5 = b] @"f541710e-34a4-4701-8902-5c68316ea153" true false
|
plan after:
[2] project [s8 = traverseP(s6, lambda(l1.0) { makeBsonObj(MakeObjSpec(keep, ["_id"], ["setEquals"]), l1.0, mql_setEquals(s4, s4, s5)) }, Nothing)]
|
[1] scan s6 s7 none none none none [s4 = a, s5 = b] @"f541710e-34a4-4701-8902-5c68316ea153" true false
|
|