5 ms·
Writing Performance Sensitive OCaml Code
- octo_t 13y agoI'm surprised the compiler goes straight to assembly, rather than targeting LLVM (most native programming languages) or C- (what GHC does/did)
- tych0 13y agoWhy? Ocaml was around long before LLVM, and GHC has a mode where you can emit assembly (and one where you can emit LLVM as well).
- deleted 13y ago[deleted]
- omaranto 13y agoMost compilers target LLVM? That doesn't sound right. Maybe most compilers written in the last five years or so.
- rwmj 13y agoThere's an OCaml LLVM backend [1]. The author found a number of issues with LLVM [2] although this could be overcome. The real problem is that the low-level object format is completely different which would break all OCaml extensions written in C (eg. any extension that links to an external C library). Plus the current code generators are really fast and cover all common architectures anyway so there's not much point. [1] https://github.com/colinbenner/ocamlllvm https://github.com/colinbenner/ocamlllvm [2] http://oud.ocaml.org/2012/abstracts/oud2012-paper7.pdf http://oud.ocaml.org/2012/abstracts/oud2012-paper7.pdf
- profquail 13y agoFYI, it's C-- (not C-): https://en.wikipedia.org/wiki/C-- https://en.wikipedia.org/wiki/C--
- masklinn 13y ago> I'm surprised the compiler goes straight to assembly, rather than targeting LLVM (most native programming languages) Most native programming languages historically don't, and OCaml predates LLVM by a good 7 years. > or C- (what GHC does/did) Cmm is an intermediate language specific to GHC before the backend[1], GHC's default backend is a native generator. [1] or more precisely "an other" intermediate language, since there's also Core.
- freyrs3 13y ago> , rather than targeting LLVM (most native programming languages) Native languages targeting LLVM are the exception not the norm. The vast majority of native compilers do emit assembly. [1] http://llvm.org/ProjectsWithLLVM/ http://llvm.org/ProjectsWithLLVM/
- MostAwesomeDude 13y agoYou might be surprised to learn that there are languages that are agnostic in what they target.
- kenko 13y agoWhy? Going to llvm constrains you to do llvm's models. (Also, the timing issue mentioned by a sibling.)
- chollida1 13y agoWow, the first 5 comments on this were about should they use LLVM:) The author is currently writing a book about OCaml that is now available in alpha format from here: http://www.realworldocaml.org/ http://www.realworldocaml.org/ I've finished the first part and looked at the compiler section, and I love this book, no affiliation in any way.
- KaeseEs 13y agoOn the one hand, OCaml is a very interesting language and I welcome a good book about it in the vein of Real World Haskell. On the other hand, it is the height of treason for O'Reilly to make a book with a camel on the cover that isn't about Perl :v
- amirmc 13y agoThey're different species of Camel. The Bactrian has two humps and the Dromedary has one (among other differences).
- flyinRyan 13y agoWhen someone/thing dies, it's ok to reuse their Jersey eventually.
- Mithaldu 13y agoHMMMM. http://www.indeed.com/jobtrends?q=perl%2C+python%2C+ruby%2C+php%2C+ocaml&l= http://www.indeed.com/jobtrends?q=perl%2C+python%2C+ruby%2C+...
- flyinRyan 13y agoNice hand-picked rebuttal. Can I play too? http://www.indeed.com/jobtrends?q=perl%2C+Java%2C+C%2B%2B%2C+C%2C+C%23%2C+go&l= http://www.indeed.com/jobtrends?q=perl%2C+Java%2C+C%2B%2B%2C... HMMMM indeed.
- 13y ago
- edwintorok 13y agoThis is a good collection of performance tips, although I'd use Unix.gettimeofday instead of RDTSC (RDTSC needs additional care on multicore). Also it is interesting that OCaml's tutorial has a section on performance (that is not something common in other language tutorials): http://ocaml.org/tutorials/performance_and_profiling.html http://ocaml.org/tutorials/performance_and_profiling.html
- toolslive 13y agoThis is a good overview of performance 'idiosyncrasies'. For profiling, I tend to use valgrind's callgrind which is easier than instrumenting the code by hand.