Skip to content

Commit 16b0f1d

Browse files
committed
interesting stuff
1 parent b2337c2 commit 16b0f1d

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

src/FastExpressionCompiler/FastExpressionCompiler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5599,13 +5599,13 @@ internal static bool TryEvalExpression(out object result, Expression expr)
55995599
return true;
56005600
}
56015601

5602-
var exprType = expr.Type;
56035602
if (nodeType == ExpressionType.Convert)
56045603
{
56055604
var unaryExpr = (UnaryExpression)expr;
56065605
var operand = unaryExpr.Operand;
56075606
if (!TryEvalExpression(out var val, operand))
56085607
return false;
5608+
var exprType = expr.Type;
56095609
result = (operand.Type == exprType || exprType.IsAssignableFrom(operand.Type)
56105610
? val
56115611
: System.Convert.ChangeType(val, exprType));

test/FastExpressionCompiler.Benchmarks/Issue468_Compile_vs_FastCompile.cs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,15 @@ public bool InvokeCompiledFast()
8080
8181
## After reverting the regression
8282
83-
83+
| Method | Job | Runtime | Mean | Error | StdDev | Ratio | RatioSD | Rank | Gen0 | Gen1 | Allocated | Alloc Ratio |
84+
|-------------------------- |--------- |--------- |----------:|----------:|----------:|------:|--------:|-----:|-------:|-------:|----------:|------------:|
85+
| Compiled | .NET 8.0 | .NET 8.0 | 25.093 us | 0.4979 us | 1.1034 us | 1.00 | 0.06 | 2 | 0.6714 | 0.6104 | 4.13 KB | 1.00 |
86+
| CompiledFast | .NET 8.0 | .NET 8.0 | 3.433 us | 0.0680 us | 0.0603 us | 0.14 | 0.01 | 1 | 0.1678 | 0.1526 | 1.12 KB | 0.27 |
87+
| CompiledFast_WithEvalFlag | .NET 8.0 | .NET 8.0 | 3.419 us | 0.0675 us | 0.1409 us | 0.14 | 0.01 | 1 | 0.2365 | 0.2289 | 1.48 KB | 0.36 |
88+
| | | | | | | | | | | | | |
89+
| Compiled | .NET 9.0 | .NET 9.0 | 25.491 us | 0.4667 us | 0.4137 us | 1.00 | 0.02 | 2 | 0.6714 | 0.6104 | 4.13 KB | 1.00 |
90+
| CompiledFast | .NET 9.0 | .NET 9.0 | 3.337 us | 0.0634 us | 0.0593 us | 0.13 | 0.00 | 1 | 0.1793 | 0.1755 | 1.12 KB | 0.27 |
91+
| CompiledFast_WithEvalFlag | .NET 9.0 | .NET 9.0 | 3.198 us | 0.0628 us | 0.0588 us | 0.13 | 0.00 | 1 | 0.2365 | 0.2289 | 1.48 KB | 0.36 |
8492
8593
*/
8694
[MemoryDiagnoser, RankColumn]
@@ -107,4 +115,10 @@ public object CompiledFast()
107115
{
108116
return _expr.CompileFast();
109117
}
118+
119+
[Benchmark]
120+
public object CompiledFast_WithEvalFlag()
121+
{
122+
return _expr.CompileFast(flags: CompilerFlags.EvaluateExpressionIfPossible);
123+
}
110124
}

0 commit comments

Comments
 (0)