DynamicExpresso icon indicating copy to clipboard operation
DynamicExpresso copied to clipboard

Prefer interpreted mode

Open dellamonica opened this issue 9 months ago • 3 comments

dotnet provides a Compile(bool preferInterpretation) variant. It is useful in scenarios where the expression is only used once. This option could be present in the API for this package as an optional parameter without breaking changes.

dellamonica avatar Apr 28 '25 18:04 dellamonica

Interesting. Do you know the difference in term of performance or memory consumption? Any other advantage or consideration?

cc @metoule @holdenmai

davideicardi avatar Apr 30 '25 08:04 davideicardi

Interesting. Do you know the difference in term of performance or memory consumption? Any other advantage or consideration?

cc @metoule @holdenmai

As with any perf question, only profiling the actual use case can give answers. However, one can expect that for expressions that are evaluated only once, the overhead of compilation might be larger than actually running an interpreter.

This comment (and thread) has other insights: https://github.com/dotnet/docs/issues/3866#issuecomment-349124653

dellamonica avatar Apr 30 '25 14:04 dellamonica

Very interesting. Considering that DynamicExpresso expressions are usually quite simple, I'm not sure they benefit much from the JIT compiler. Also, I believe that most users rely on the Eval method that only executes the expression once.

I have to perform stronger benchmarks, but it has a nice impact on the unit tests execution time. Excluding the massive LiteralsTest.Non_Ascii_Chars, the execution time decreases by roughly 10 to 15%.

LiteralsTest.Non_Ascii_Chars goes from about 5s to about 1s.

To roll this out, I think we can set it to true for all calls to Eval, and offer the option for the other use cases. I'll see how we can revisit the Lambda public API to better reflect the intent.

metoule avatar May 05 '25 10:05 metoule