Skip to content

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

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

Tushar-Naik
Copy link
Contributor

…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);
Copy link
Contributor Author

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

Copy link
Contributor Author

@Tushar-Naik Tushar-Naik Apr 23, 2025

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

@Tushar-Naik Tushar-Naik requested a review from zodvik April 23, 2025 18:50
}

private Boolean valueInValueSet(List<Object> values, Set<Object> valueSet) {
if (!isNotEmpty(values)) {
Copy link
Contributor

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;
Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants