Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Investigate the possibility to use the Groovy interpreter + static evaluation to interpret a simple subset of KernelF #1039

Open
alexanderpann opened this issue Aug 17, 2024 · 0 comments

Comments

@alexanderpann
Copy link
Member

alexanderpann commented Aug 17, 2024

The interpreter language is very slow. The main reason is that it has to evaluate the child constraints of the evaluators, which means checking the types for many nodes. Moreover, calculations on long collections are not optimized and take nearly linear time.
For many use cases, the basic concepts of KernelF that are needed (e.g. arithmetic/list operations etc) could be translated to Groovy and evaluated by the Groovy Script Engine that is shipped with the JBR or IntelliJ platform. Example:
KernelF (> 1000 ms):
10.upto(5000).map(|it: number{0} => it * 2|).where(|it >= 50|).size
Groovy (~7 ms):

Class<?> eval = Class.forName("groovy.util.Eval"); 
Method meMethod = eval.getMethod("me", String.class); 
Instant start = Instant.now(); 
#print meMethod.invoke(null, "(10..5000-1).collect { it * 2 }.findAll { it >= 50 }.size()"); 
Instant finish = Instant.now(); 
long timeElapsed = Duration.between(start, finish).toMillis(); 
#print "Time:" + timeElapsed + " ms"; 

The cost of translating the expression to Groovy is probably still less expensive than iteratively evaluating the collection with our interpreter. For simple expressions like "1+1" the overhead is too big, but for cases where the result is statically evaluable we could evaluate them directly in behavior methods the same way it is implemented in Base Language.

For more complicated expressions, we could maybe also jump out of the interpreter back to static evaluation if this brings any performance advantages.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant