Skip to content

Conversation

fiseni
Copy link
Collaborator

@fiseni fiseni commented Mar 1, 2025

Fixes #421
Fixes #422
Fixes #424

  • Improved the nullability in search expressions.
  • Improved the C# implementation of Like. Introduced caching for regex objects.
  • Updated SearchValidator to allocation-free implementation. For larger input collections, the difference is drastic. For 1000 entities, the allocations are reduced from 651.160 bytes to ZERO bytes.
  • Updated SeatchMemoryEvaluator and decreased allocations (constant allocation size regardless of input). Added custom iterator implementation. For larger input collections, the difference is drastic. For a source of 1000 items, the allocations are reduced from 257.872 bytes to only 56 bytes (the cost of the custom iterator instance).

@fiseni fiseni requested a review from ardalis March 1, 2025 20:35
Copy link
Owner

@ardalis ardalis left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good; couple minor questions


private IEnumerator<TSource>? _enumerator;

public SpecLikeIterator(IEnumerable<TSource> source, List<SearchExpressionInfo<TSource>> searchExpressions)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not switching to primary constructor syntax yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been hesitant because of the older TFMs. We need to check whether we need any polyfills or not (I assume not).

{
if (_searchExpressions is null)
{
_searchExpressions = new(2) { searchExpression };
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Replace magic number 2 with meaningful named constant?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This represents the initial capacity. And it can be different for each collection, for example we may choose for Where to be 4, for Search 2, etc. We need to introduce 6-7 constants, and not sure whether that makes it better or worse.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated to use constants.

@ardalis ardalis merged commit 0e7a338 into main Mar 3, 2025
1 check passed
@fiseni fiseni deleted the fiseni/search-improvements branch March 3, 2025 15:41
This was referenced Sep 2, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
2 participants