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

Experiment: Generating OCaml instead of SML #466

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from

Conversation

b-studios
Copy link
Collaborator

@b-studios b-studios commented May 23, 2024

Just a draft for now.

While it is somewhat feature complete wrt to the old MLTon backend, there is still a lot to do:

  • identify recursive groups and introduce let rec ... and ... binding groups for those (and those only).
  • model capabilities / objects using records since this allows rank-2 types (https://soap.coffee/~lthms/posts/RankNTypesInOCaml.html)
  • Implement heterogenous regions (since in OCaml we have Obj.magic)

@b-studios b-studios changed the title Experiments generating ocaml instead of sml Experiment: Generating OCaml instead of SML May 24, 2024
@b-studios
Copy link
Collaborator Author

b-studios commented May 24, 2024

This was easier than expected.

@phischu if you are interested, you could benchmark this to compare it to our MLTon implementation used at https://github.com/effect-handlers/effect-handlers-bench

This way we could estimate how well the (global) optimizations performed by MLton perform compared to OCaml.

To get a first idea, here are the results of running examples/benchmark/nqueens on both:

hyperfine "./out/ocaml-main 12" "./out/mlton-main 12"
Benchmark 1: ./out/ocaml-main 12
  Time (mean ± σ):      4.070 s ±  0.002 s    [User: 4.060 s, System: 0.008 s]
  Range (min … max):    4.067 s …  4.075 s    10 runs

Benchmark 2: ./out/mlton-main 12
  Time (mean ± σ):     101.5 ms ±   0.5 ms    [User: 100.1 ms, System: 0.7 ms]
  Range (min … max):   100.7 ms … 103.0 ms    28 runs

Summary
  './out/mlton-main 12' ran
   40.10 ± 0.21 times faster than './out/ocaml-main 12'

Mlton is roughly 40x faster.

Using ocamlopt instead of ocamlc gives only a slowdown of 6x over mlton:

hyperfine "./out/ocaml-main 12" "./out/mlton-main 12"
Benchmark 1: ./out/ocaml-main 12
  Time (mean ± σ):     683.0 ms ±   1.9 ms    [User: 679.9 ms, System: 2.3 ms]
  Range (min … max):   681.7 ms … 687.5 ms    10 runs

Benchmark 2: ./out/mlton-main 12
  Time (mean ± σ):     101.2 ms ±   0.4 ms    [User: 100.0 ms, System: 0.7 ms]
  Range (min … max):   100.7 ms … 102.5 ms    28 runs

Summary
  './out/mlton-main 12' ran
    6.75 ± 0.03 times faster than './out/ocaml-main 12'

@b-studios b-studios added the experiment Experimental branch, do not merge! label Aug 30, 2024
@jiribenes jiribenes force-pushed the master branch 3 times, most recently from ee9d209 to 58c8510 Compare October 1, 2024 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
experiment Experimental branch, do not merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant