Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's faster: expression trees or manually emitting IL

Is there a performance difference between creating a method emitting IL directly, as opposed to building an expression tree?

like image 422
sircodesalot Avatar asked May 13 '13 20:05

sircodesalot


1 Answers

Excellent and complex question. Prior to recently, Expression simply could not handle all scenarios - so in many cases it was a non-question. This changes with the introduction of Expression.Block etc. In most "common" cases, the Expression usage is probably more than sufficient, but I confess I do not have precise measurements, simply for the reason that while I do lots of IL, I also target down-level frameworks which do not have luxuries like Expression (and certainly not Expression.Block). I also tend to use complex "decorator" approaches that lend themselves nicely to stack gymnastics in IL, but not necessarily into Expression (indeed, if your IL is atypical enough that reflector et al struggle with it, then it probably also doesn't map cleanly to Expression - and my IL tends to be pretty gnarly).

Sorry, I can't give you more numeric data - key points:

  • if you have down-level framework requirements the question is moot
  • otherwise, you'd have to profile
like image 108
Marc Gravell Avatar answered Sep 20 '22 14:09

Marc Gravell