rems-project / sail

Sail architecture definition language
Other
617 stars 112 forks source link

OCaml RISC-V model takes many minutes to build with OCaml 4.14 #209

Open arichardson opened 1 year ago

arichardson commented 1 year ago

I noticed that building the OCaml simulators for sail(-cheri)-riscv takes multiple minutes (in some builds up to 10 minutes per target) after switching to sail built with OCaml 4.14.0 and 4.14.1. Using 4.13.1 instead allows me to build all the sail-cheri-riscv models (C+OCaml) in two minutes.

I'm not sure if there is anything sail can do about the generated code here, or if this is purely an upstream OCaml issue. Seems to me that we are hitting some threshold after which the compiler does not scale well.

Alasdair commented 1 year ago

We might be generating some very large functions from scattered definitions, that might be stressing the compiler in a way that most hand-written code wouldn't.

PeterSewell commented 1 year ago

If there's a big perf regression, it might be worth raising it with the OCaml devs - though they may not be too sympathetic for generated code

On Tue, 14 Feb 2023 at 12:37, Alasdair Armstrong @.***> wrote:

We might be generating some very large functions from scattered definitions, that might be stressing the compiler in a way that most hand-written code wouldn't.

— Reply to this email directly, view it on GitHub https://github.com/rems-project/sail/issues/209#issuecomment-1429682356, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABFMZZQYQHZV34FNIWBZHM3WXN4B3ANCNFSM6AAAAAAU2TI5ZI . You are receiving this because you are subscribed to this thread.Message ID: @.***>

Alasdair commented 1 year ago

It might be the string append patterns (which has absurdly bad code generation that produces about 99% of the OCaml code in the model). Because the string append stuff works so poorly, we strictly require that all uses can be deleted as dead code. The OCaml backend doesn't do any dead-code elimination so it doesn't benefit from that like the C backend does.

If it's not the string_append thing, it's probably the big decode and execute functions. We already have a rewrite to split them up again, so if it's that we could just try turning that rewrite on for OCaml.