8000 Improve the Search in-memory evaluator. Implement a custom iterator and reduce allocations. · Issue #422 · ardalis/Specification · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
Improve the Search in-memory evaluator. Implement a custom iterator and reduce allocations. #422
Closed
@fiseni

Description

@fiseni

The current SearchMemoryEvaluator implementation is as follows.

public IEnumerable<T> Evaluate<T>(IEnumerable<T> query, ISpecification<T> specification)
{
    foreach (var searchGroup in specification.SearchCriterias.GroupBy(x => x.SearchGroup))
    {
      query = query.Where(x => searchGroup.Any(c => c.SelectorFunc(x).Like(c.SearchTerm)));
    }

    return query;
}

This looks relatively simple, but there are a lot of hidden allocations. Moreover, the number of allocations is not constant, and it depends on the size of the input collection.

We need to implement a custom iterator and come up with an allocation-free GroupBy implementation. We may keep the search expressions sorted by search group, and then slice to get the groups.

Breaking Changes:
The SearchEvaluator was renamed to SearchMemoryEvaluator. It was causing unnecessary name collisions with EF plugin evaluators.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions

    0