Stepping that code, it seem to me that many expression visits are done for each query (even if not always of the same expression tree), is this true?
Wouldn't be possible to use a single pass (that probably would require less time, allowing to remove the cache)?
To handle different trees (like the VB ones) couldn't we use different analizers?
Moreover are we sure that optimization don't take too much time (ehm... and what are constant subexpressions? :-D)
I think that, if we could leave Expression unmuted, we would gain a very big performance advantage.
That said, supposing we need to keep the current process, the updated closure values are in the original compiler produced tree.
To not add another expression tree visit (even if it would probably be a lot faster since it should only handle inputparameterexpressions), we should be able to keep track of the current tree node analized: how would you do to pass such info among transformated expressions?
Giacomo