call vs execute
Stefan Fehrenbach
stefan.fehrenbach at gmail.com
Tue Jun 24 08:20:16 UTC 2014
Hello,
I implemented a recursive descend grammar interpreter using Truffle.
Nonterminal calls are replaced by either of three alternative implementations:
1. Unoptimized lookup of the nonterminal in a hash table
2. Look up nonterminal during replacement, cache result and call the
cached node's execute method directly.
3. Look up nonterminal during replacement, cache result and use
Truffle's function call support to call the execute method.
Now it happens that the function call variant is a lot slower than the
other two and even the cached variant is still slower than the naive
implementation:
Unoptimized: 3095
Cached execute: 3555
Cached call: 18521
(Time to parse a long string with a grammar consisting of a long chain
of nonterminal calls a couple of times.)
My question is: why is the function call variant so much slower? The
actual computation is so simple, I expected Truffle/Graal to just
inline the functions.
And why is the cached variant still slower than the naive
implementation. In every parse, we need 150*150 hash table look ups in
the naive implementation vs only 150*150 Assumption checks in variant
#2.
Code is here: https://github.com/fehrenbach/parsers
Uninitialized node:
https://github.com/fehrenbach/parsers/blob/master/src/org/morphling/parsers/truffle/UninitializedNonterminalCall.java
I use the graalvm-jdk1.8.0-0.3 release and the following JVM
parameters to call this main method:
org.morphling.parsers.truffle.Tests#main
-server
-Xss32m
-Dtruffle.TraceRewrites=true
-Dtruffle.DetailedRewriteReasons=true
-G:+TraceTruffleCompilationDetails
-G:+TraceTruffleCompilation
-G:TruffleCompilationThreshold=1
-XX:+UnlockDiagnosticVMOptions
-XX:-PrintCompilation
Am I just using Truffle the wrong way? What could be the reason for
the slow function calls and the underperforming cache, even in this
contrived grammar with long nonterminal chains?
Best regards,
Stefan
More information about the graal-dev
mailing list