Skip to content

Commit

Permalink
v2.4.4 (#46)
Browse files Browse the repository at this point in the history
* Fix BuildCompiledEvaluator performance issue

* add QueryBuilderEvaluatorBenchmark and last run result

* fix ElementType error, issue #45

* update to v2.4.4
  • Loading branch information
alirezanet authored Nov 20, 2021
1 parent 0b3946b commit eda22ff
Show file tree
Hide file tree
Showing 8 changed files with 91 additions and 7 deletions.
17 changes: 17 additions & 0 deletions benchmark/LibraryComparisionFilteringBenchmark.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,20 @@ public static IEnumerable<TestClass> GetSampleData()
}
}
}

/* Last Run:
BenchmarkDotNet=v0.13.0, OS=Windows 10.0.19043.1237 (21H1/May2021Update)
11th Gen Intel Core i5-11400F 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=5.0.301
[Host] : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
DefaultJob : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
| Method | Mean | Error | StdDev | Ratio | Gen 0 | Gen 1 | Allocated |
|------------ |-----------:|---------:|---------:|------:|--------:|--------:|----------:|
| Native LINQ | 740.9 us | 7.80 us | 6.92 us | 1.00 | 5.8594 | 2.9297 | 37 KB |
| Gridify | 762.6 us | 10.06 us | 9.41 us | 1.03 | 5.8594 | 2.9297 | 39 KB |
| DynamicLinq | 902.1 us | 11.56 us | 10.81 us | 1.22 | 19.5313 | 9.7656 | 122 KB |
| Sieve | 977.9 us | 6.80 us | 6.37 us | 1.32 | 7.8125 | 3.9063 | 54 KB |
| Fop | 2,959.8 us | 39.11 us | 36.58 us | 3.99 | 46.8750 | 23.4375 | 306 KB |
*/
5 changes: 3 additions & 2 deletions benchmark/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@ public class Program
{
private static void Main()
{
// BenchmarkRunner.Run<LibraryComparisionFilteringBenchmark>();
BenchmarkRunner.Run<QueryBuilderBuildBenchmark>();
BenchmarkRunner.Run<LibraryComparisionFilteringBenchmark>();
// BenchmarkRunner.Run<QueryBuilderBuildBenchmark>();
// BenchmarkRunner.Run<QueryBuilderEvaluatorBenchmark>();
Console.Read();
}
}
Expand Down
61 changes: 61 additions & 0 deletions benchmark/QueryBuilderEvaluatorBenchmark.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.Linq;
using BenchmarkDotNet.Attributes;
using BenchmarkDotNet.Engines;
using BenchmarkDotNet.Order;
using Gridify;
using Gridify.Tests;

namespace Benchmarks
{
[MemoryDiagnoser]
[RPlotExporter]
[Orderer(SummaryOrderPolicy.FastestToSlowest)]
public class QueryBuilderEvaluatorBenchmark
{
private readonly IEnumerable<TestClass> _data;
// private static readonly Consumer Consumer = new();
private readonly Func<IQueryable<TestClass>,bool> BuildEvaluatorFunc;
private readonly Func<IEnumerable<TestClass>,bool> BuildCompiledEvaluatorFunc;

public QueryBuilderEvaluatorBenchmark()
{
_data = LibraryComparisionFilteringBenchmark.GetSampleData().ToArray();

var builder = new QueryBuilder<TestClass>()
.AddCondition("id>2")
.AddCondition("name=*a");

BuildEvaluatorFunc = builder.BuildEvaluator();
BuildCompiledEvaluatorFunc = builder.BuildCompiledEvaluator();
}

[Benchmark]
public void BuildEvaluator()
{
BuildEvaluatorFunc(_data.AsQueryable());
}

[Benchmark]
public void BuildCompiledEvaluator()
{
BuildCompiledEvaluatorFunc(_data);
}

}
}

/* Last Run:
BenchmarkDotNet=v0.13.0, OS=Windows 10.0.22000
11th Gen Intel Core i5-11400F 2.60GHz, 1 CPU, 12 logical and 6 physical cores
.NET SDK=6.0.100
[Host] : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
DefaultJob : .NET 5.0.7 (5.0.721.25508), X64 RyuJIT
| Method | Mean | Error | StdDev | Gen 0 | Gen 1 | Gen 2 | Allocated |
|----------------------- |-------------:|------------:|------------:|-------:|-------:|------:|----------:|
| BuildCompiledEvaluator | 104.3 ns | 2.07 ns | 2.38 ns | 0.0305 | - | - | 192 B |
| BuildEvaluator | 466,066.5 ns | 4,392.92 ns | 4,109.14 ns | 3.4180 | 1.4648 | - | 23,475 B |
*/
2 changes: 1 addition & 1 deletion src/Gridify.EntityFramework/Gridify.EntityFramework.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Gridify.EntityFramework</PackageId>
<Version>2.4.3</Version>
<Version>2.4.4</Version>
<Authors>Alireza Sabouri</Authors>
<Company>TuxTeam</Company>
<PackageDescription>Gridify (EntityFramework), Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.</PackageDescription>
Expand Down
2 changes: 1 addition & 1 deletion src/Gridify/Gridify.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Gridify</PackageId>
<Version>2.4.3</Version>
<Version>2.4.4</Version>
<Authors>Alireza Sabouri</Authors>
<Company>TuxTeam</Company>
<PackageDescription>Gridify, Easy and optimized way to apply Filtering, Sorting, and Pagination using text-based data.</PackageDescription>
Expand Down
2 changes: 1 addition & 1 deletion src/Gridify/QueryBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ public Func<IQueryable<T>, bool> BuildEvaluator()
/// <inheritdoc />
public Func<IEnumerable<T>, bool> BuildCompiledEvaluator()
{
var compiledCond = _conditions.Select(q => q.Compile() as Func<T, bool>);
var compiledCond = _conditions.Select(q => q.Compile() as Func<T, bool>).ToList();
var length = _conditions.Count;
return collection =>
{
Expand Down
7 changes: 6 additions & 1 deletion src/Gridify/Syntax/SyntaxTreeToQueryConvertor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,12 @@ private static LambdaExpression GetAnyExpression(MemberExpression member, Expres
var param = GetParameterExpression(member);
var prop = Expression.PropertyOrField(param!, member.Member.Name);

var tp = prop.Type.GenericTypeArguments[0];
var tp = prop.Type.IsGenericType
? prop.Type.GenericTypeArguments.First() // list
: prop.Type.GetElementType(); // array

if (tp == null) throw new GridifyFilteringException($"Can not detect the '{member.Member.Name}' property type.");

var anyMethod = GetAnyMethod(tp);
var anyExp = Expression.Call(anyMethod, prop, predicate);

Expand Down
2 changes: 1 addition & 1 deletion test/Gridify.Tests/Issue36Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public class Level1
{
public string Name { get; set; }

public List<Level2> Level2List = new List<Level2>()
public Level2[] Level2List = new Level2[]
{
new Level2()
{
Expand Down

0 comments on commit eda22ff

Please sign in to comment.