idris-lang / Idris-dev

A Dependently Typed Functional Programming Language
http://idris-lang.org
Other
3.43k stars 643 forks source link

Investigate the performance penalty of compiling via C #3240

Open DemiMarie opened 8 years ago

DemiMarie commented 8 years ago

The GHC devs found that compiling via C cost a factor of ~2 in performance, except when they used the so-called "evil mangler" (now removed) and GCC-specific global register variables to emulate a custom calling convention. GHC now compiles via LLVM or a native code generator, and uses the same custom calling convention in both cases.

Idris can probably just use the GHC calling convention. In fact, I believe that one of GHC's intermediate representations (either Core or Cmm) might be a good backend target – it would also allow Idris to take advantage of the GHC RTS.

There is an LLVM backend for Idris but it dates back to 2014.

yacinehmito commented 8 years ago

You might be interested in an experimental OCaml backend. It takes advantage of the OCaml compiler optimizations and the OCaml GC.

jfdm commented 8 years ago

@DemiMarie Thank you for the feature request.

One of the many nice features of the Idris compiler is the ability to re-target the compiler. It allows for Idris to be retargeted to Java, CLR, LLVM, PHP, Python, OCaml, C, Javascript, and Ruby. Unfortunately, supporting a backend does require time and effort, and knowledge of the target language. This was the reason why the Java and LLVM backends were spun out to Idris Hackers, and the majority of the other mentioned backends are community driven. Furthermore, some researchers are using code targets as part of their research.

However, as the language is still being developed, priorities tend to be towards correctness of the implementation, rather than efficiency of said implementation. Supporting a backend requires effort, and more effort to develop a backend from scratch. So, it is better to keep a small set of 'officially' supported and tested backends, (namely the C and Javascript) and keep the technical debt to a minimum until the language is more or less stable. When the language becomes more stable, then maybe there might be time to look at adding a new backend.

With all that said, you are more than welcome to ask questions about how to build a backend on our IRC channel (or mailing list), if you wish to drive this endeavour. We always welcome community contributions.