This project has moved. For the latest updates, please go here.

Serialise/Persist compiled expressions

Sep 1, 2014 at 8:41 AM
Edited Sep 1, 2014 at 1:23 PM
For most Line-Of-Business applications, expressions entered by the end users are repetitively used against good number of objects. If we ScopeCompile all expressions at application start and cache them in a container, will improve overall performance.

Further performance enhancement can be done if we could serialise/persist and reload them at application start. I guess LambdaExpression.Compile anyway generates IL, so a call to compile at app-start could be sufficient to generate IL. However, this would require CompiledExpression to "load" already compiled expression.

Request your thoughts.

Thanks,
Kinjal
Developer
Sep 4, 2014 at 8:36 AM
Edited Sep 4, 2014 at 8:43 AM
sharewithkinjal wrote:
For most Line-Of-Business applications, expressions entered by the end users are repetitively used against good number of objects. If we ScopeCompile all expressions at application start and cache them in a container, will improve overall performance.
Yes, this is generally the way to speed up things. Either cache on compile, when the expression is first encountered, or cache in advance.
Further performance enhancement can be done if we could serialise/persist and reload them at application start. I guess LambdaExpression.Compile anyway generates IL, so a call to compile at app-start could be sufficient to generate IL. However, this would require CompiledExpression to "load" already compiled expression.
I don't know if there's a way to serialize and deserialize IL like that.

EDIT: There seems to be a way, but I am not sure if it can be done with a delegate method.

http://stackoverflow.com/questions/346111/is-it-possible-to-serialize-a-c-sharp-code-block