Skip to content

Commit 726d5ff

Browse files
committed
beam_core_to_ssa: Eliminate bottleneck when there are many clauses
When a `case` had many clauses (say hundred thousand or more) having all the same body, the beam_core_to_ssa pass could become very slow.
1 parent b198256 commit 726d5ff

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

lib/compiler/src/beam_core_to_ssa.erl

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2599,8 +2599,14 @@ select_val_cg(Type, R, Vls, Tf, Vf, Sis, St0) ->
25992599
{TypeIs++[#b_switch{arg=R,fail=Vf,list=Vls}|Sis],St1}
26002600
end.
26012601

2602-
combine([{Is,Vs1},{Is,Vs2}|Vis]) -> combine([{Is,Vs1 ++ Vs2}|Vis]);
2603-
combine([V|Vis]) -> [V|combine(Vis)];
2602+
2603+
combine([V|Vis0]) ->
2604+
case {V, combine(Vis0)} of
2605+
{{Is,Vs1}, [{Is,Vs2}|Vis]} ->
2606+
[{Is,Vs1 ++ Vs2}|Vis];
2607+
{_,Vis} ->
2608+
[V|Vis]
2609+
end;
26042610
combine([]) -> [].
26052611

26062612
select_labels([{Is,Vs}|Vis], St0, Vls, Sis) ->

0 commit comments

Comments
 (0)