Skip to content

Commit d1f9b14

Browse files
committed
Do more aggressive lambda lifting
With @vouillon we realized that the `Lambda_lifting_simple` pass that is performed by double translation makes some programs significantly faster. We measured roughly a 1.45 speedup on a large (proprietary) Bonsai benchmark. Presumably V8 is much faster with more toplevel functions and less nested closures.
1 parent dcec0ac commit d1f9b14

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

compiler/lib/driver.ml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,17 @@ let effects_and_exact_calls
165165
Deadcode.f pure_fun p
166166
else Deadcode.f pure_fun p
167167
in
168+
let p =
169+
match Config.(target (), effects ()) with
170+
| `JavaScript, `Disabled ->
171+
(* If effects are disabled, we lambda-lift aggressively. While not
172+
necessary, it results in a substantial gain in performance in some
173+
programs in Javascript. *)
174+
let to_lift = all_functions p in
175+
let p, _ = Lambda_lifting_simple.f ~to_lift p in
176+
p
177+
| _ -> p
178+
in
168179
match Config.effects () with
169180
| `Cps | `Double_translation ->
170181
if debug () then Format.eprintf "Effects...@.";
@@ -696,6 +707,16 @@ let link_and_pack ?(standalone = true) ?(wrap_with_fun = `Iife) ?(link = `No) p
696707
|> pack ~wrap_with_fun ~standalone
697708
|> check_js
698709

710+
let all_functions p =
711+
let open Code in
712+
fold_closures
713+
p
714+
(fun name _ _ _ acc ->
715+
match name with
716+
| Some name -> Var.Set.add name acc
717+
| None -> acc)
718+
Var.Set.empty
719+
699720
let optimize ~shapes ~profile ~keep_flow_data p =
700721
let deadcode_sentinal =
701722
(* If deadcode is disabled, this field is just fresh variable *)

0 commit comments

Comments
 (0)