Skip to content

Commit 9ab99e3

Browse files
committed
Expanding a definition used as a macro in CClosure.
While thought as a macro, the with_stats function was calling lazy + Lazy.force, which has a remarkable cost in the implementation, as it allocates and breaches the write barrier. We simply expand the definition twice, breaking the abstraction but gaining in performance.
1 parent b958dfa commit 9ab99e3

File tree

1 file changed

+14
-2
lines changed

1 file changed

+14
-2
lines changed

kernel/cClosure.ml

+14-2
Original file line numberDiff line numberDiff line change
@@ -1059,11 +1059,23 @@ and norm_head_array info env n (v : constr array) =
10591059

10601060
(* weak reduction *)
10611061
let whd_val info v =
1062-
with_stats (lazy (term_of_fconstr (kh info v [])))
1062+
if !stats then begin
1063+
reset();
1064+
let r = term_of_fconstr (kh info v []) in
1065+
stop();
1066+
r
1067+
end else
1068+
term_of_fconstr (kh info v [])
10631069

10641070
(* strong reduction *)
10651071
let norm_val info v =
1066-
with_stats (lazy (kl info v))
1072+
if !stats then begin
1073+
reset();
1074+
let r = kl info v in
1075+
stop();
1076+
r
1077+
end else
1078+
kl info v
10671079

10681080
let inject c = mk_clos (subs_id 0) c
10691081

0 commit comments

Comments
 (0)