[antlr-interest] alternatives to linq LambdaExpression Compile method

Sam Harwell sharwell at pixelminegames.com
Tue Jul 5 07:03:55 PDT 2011


Hi Costa,

There are three options which I might suggest, with the first two being
vastly preferred to the last. First of all, you should review your current
code to make sure that if a formula gets evaluated multiple times, the
compiled expression (Func<T> delegate) is reused. I've successfully used
that Compile method as part of a fairly expensive finite element computation
program with surprisingly great results. :)

Second, if your expressions are not always the same but can be factored as
in f(x)=3*x and g(x)=2*x, the you can instead create a reusable h(x, y)=x*y
which would have much better results.

If for some reason the above do not work well in your situation, I privately
have a version of ASMJIT written entirely in C# which can directly emit x86
and/or x64 code (without parsing intermediate assembly language files) that
is then called through a delegate. Depending on your needs, I might be able
to work out a commercial license for its use. This library can certainly
produce fast code, but it's extremely difficult both to get correct and to
debug.

Sam

-----Original Message-----
From: antlr-interest-bounces at antlr.org
[mailto:antlr-interest-bounces at antlr.org] On Behalf Of Costa Basil
Sent: Tuesday, July 05, 2011 2:17 AM
To: antlr-interest at antlr.org
Subject: [antlr-interest] alternatives to linq LambdaExpression Compile
method

I have a program that has to compile and execute formulas on the fly. I am
using antlr to build linq expression trees which I then compile using the
LambdaExpression.Compile() method.

The problem is that this method is far too slow. Are there any other
alternatives perhaps commercial that would be faster?

Any other suggestions?

Thanks

List: http://www.antlr.org/mailman/listinfo/antlr-interest
Unsubscribe:
http://www.antlr.org/mailman/options/antlr-interest/your-email-address



More information about the antlr-interest mailing list