trifork / erjang

A JVM-based Erlang VM
http://www.erjang.org
Apache License 2.0
726 stars 62 forks source link

Reduce Pausable methods in beam->jvm codegen #21

Closed krestenkrab closed 14 years ago

krestenkrab commented 14 years ago

In the beam->jvm codegen, I think we can make the code gen more efficient by making a separate pass on an entire module to determine which functions need to be Pausable.

All functions are encoded as static members of the module class, and non-external calls between functions in the same module thus are direct static calls. Now, if we can determine methods (typically leafs in the call graph) which do not call external functions, and which do not use BIFs that are Pausable, and make those functions also be non-Pausable, then it would reduce the overhead generated by Kilim significantly; and potentially speed up things quite significantly.

Such a pass needs to build a dependency graph containing all intra-module calls, and scan functions for BIFs or external calls. The "Pausable"ness then needs to flow backwards in that dependency graph.

eriksoe commented 14 years ago

The dependency graph need not even be built explicitly; a depth-first traversal of the call graph can be done without it. (Of course, if there are other potential uses of an explicit representation of the dependency graph, then it's another matter.)

krestenkrab commented 14 years ago

I implemented this in ModuleAnalyzer, and also the codegen to support it. For a few modules we can even make ALL functions non-pausable! I also support checking for tailrecursive-ness, so that function that are not tail recursive need not have the invocation loop when called locally.