-
Notifications
You must be signed in to change notification settings - Fork 0
refactor: replace List with Set for filter values in JsonPath evaluat… #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
…ion, including other optimizations of loops over streams
@@ -199,17 +211,29 @@ public Boolean visit(GenericFilter filter) { | |||
|
|||
|
|||
private <T> Boolean applyAllMatchFilter(Filter filter, TypeRef<List<T>> typeRef, Predicate<T> predicate) { | |||
List<T> nonNullValues = nonNullValues(filter, typeRef); | |||
return isNotEmpty(nonNullValues) && nonNullValues.stream().allMatch(predicate); | |||
List<T> values = readContextValues(filter, typeRef); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Benchmark Mode Cnt Score Error Units
JsonPathEvalBenchmark.newerImpl thrpt 5 4319391.869 ± 107293.083 ops/s
JsonPathEvalBenchmark.olderImpl thrpt 5 3545470.314 ± 133759.198 ops/s
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This benchmark only includes this function, and excludes the List->Set conversion from query-dsl. That would be added improvement
|
} | ||
|
||
private Boolean valueInValueSet(List<Object> values, Set<Object> valueSet) { | ||
if (!isNotEmpty(values)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit for later - remove double negative
List<T> values = context.documentContext().read(filter.getField(), typeRef); | ||
if (log.isTraceEnabled()) { | ||
log.trace(BONSAI_FILTER_VALUES_DOCUMENT_LOG_STR, context.id(), filter.getField(), values, | ||
context.documentContext().json()); | ||
} | ||
return values == null ? Collections.emptyList() : values.stream().filter(Objects::nonNull).toList(); | ||
return values == null ? Collections.emptyList() : values; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not filter for non null here? This then needs all callers to check for null
.
…ion, including other optimizations of loops over streams