jcoglan commented on code in PR #6080:
URL: https://github.com/apache/couchdb/pull/6080#discussion_r3949712935
##########
src/mango/src/mango_selector.erl:
##########
@@ -548,22 +689,139 @@ match({[{<<"$", _/binary>> = Op, _}]}, _, _) ->
% We need to traverse value to find field. The call to
% mango_doc:get_field/2 may return either not_found or
% bad_path in which case matching fails.
-match({[{Field, Cond}]}, Value, Cmp) ->
+match({[{Field, Cond}]}, Value, #ctx{verbose = Verb, path = Path} = Ctx) ->
+ InnerPath = extend_path(Field, Path),
Review Comment:
I've run the couple of benchmarks I put in before doing this work, against
the `main` branch, against this branch as-is, and after a change to only modify
the `Ctx` if `Verb = true`; these are the results (higher is better, each
column is a set of readings and the mean value):
apache/main:
and: normal | and: verbose | allMatch: normal | allMatch: verbose
------------- | --------------- | ------------------- | -----------------
3373312 | n/a | 2116779 | n/a
3506853 | | 2116407 |
3177151 | | 1887538 |
3381903 | | 1948357 |
3615163 | | 2080386 |
------------- | --------------- | ------------------- | -----------------
3410876 | | 2029893
this branch:
and: normal | and: verbose | allMatch: normal | allMatch: verbose
------------- | --------------- | ------------------- | -----------------
3219631 | 601439 | 3085928 | 647014
3077505 | 594021 | 3105148 | 642489
3088902 | 591180 | 3163921 | 647481
3551507 | 687608 | 3034273 | 673736
3208026 | 598050 | 3069272 | 662754
------------- | --------------- | ------------------- | -----------------
3229114 | 614459 | 3091708 | 654694
with InnerCtx optimisation:
and: normal | and: verbose | allMatch: normal | allMatch: verbose
------------- | --------------- | ------------------- | -----------------
3534877 | 618352 | 3385474 | 624247
3786131 | 686324 | 3426165 | 692269
3582253 | 662680 | 3417704 | 779013
3779435 | 666856 | 3419047 | 754569
3634909 | 657130 | 3471058 | 673272
------------- | --------------- | ------------------- | -----------------
3663521 | 658268 | 3423889 | 704674
Without the optimisation, `$and` runs ~5% slower and `$allMatch` ~50%
faster. With a change to how `InnerCtx` is handled, `$and` is ~7% faster than
`main` while `$allMatch` is almost 70% faster.
It makes sense that `$and` would have been impacted by this b/c `{x: {$and:
[A, B, C]}}` normalises to `{$and: [{x: A}, {x: B}, {x: C}]}` i.e. field
accesses are pushed down the tree and get duplicated as a result. So,
optimisations to field accesses can have a major impact.
The updates I'm pushing include a new commit that only changes the `Ctx`
value if `Verb = true`.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]