Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:Ledest:erlang:23
erlang
5521-v3_core-Reduce-the-compile-time-for-functi...
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File 5521-v3_core-Reduce-the-compile-time-for-functions-with-m.patch of Package erlang
From ce631306b46b1cc39c6b046a876f38606b2ae652 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= <bjorn@erlang.org> Date: Fri, 21 Jan 2022 08:33:52 +0100 Subject: [PATCH] v3_core: Reduce the compile time for functions with many variables This commit will shave off a few seconds for the `v3_core` pass for the example in #5140. --- lib/compiler/src/v3_core.erl | 36 ++++++++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/compiler/src/v3_core.erl b/lib/compiler/src/v3_core.erl index 8e89c88318..7727d4e5b0 100644 --- a/lib/compiler/src/v3_core.erl +++ b/lib/compiler/src/v3_core.erl @@ -2486,12 +2486,48 @@ uexprs([#imatch{anno=A,pat=P0,arg=Arg,fc=Fc}|Les], Ks, St0) -> uexprs([#icase{anno=A,args=[Arg], clauses=[Mc],fc=Fc}], Ks, St0) end; +uexprs([#iset{}|_]=Les0, Ks0, St0) -> + uexprs_iset(Les0, [], Ks0, St0); uexprs([Le0|Les0], Ks0, St0) -> {Le1,St1} = uexpr(Le0, Ks0, St0), {Les1,Ks,St2} = uexprs(Les0, known_union(Ks0, (get_anno(Le1))#a.ns), St1), {[Le1|Les1],Ks,St2}; uexprs([], Ks, St) -> {[],Ks,St}. +%% Since the set of known variables can grow quite large, try minimize +%% the number of union operations on it. +uexprs_iset([#iset{anno=A0,var=V,arg=Arg0}=Le0|Les0], New0, Ks0, St0) -> + case uexpr_need_known(Arg0) of + true -> + Ks1 = known_union(Ks0, New0), + {Le1,St1} = uexpr(Le0, Ks1, St0), + New = (get_anno(Le1))#a.ns, + {Les1,Ks,St2} = uexprs_iset(Les0, New, Ks1, St1), + {[Le1|Les1],Ks,St2}; + false -> + %% We don't need the set of known variables when processing + %% Arg0, so we can postpone the call to known_union/2. This + %% will save time for functions with a huge number of variables. + {Arg,St1} = uexpr(Arg0, none, St0), + #a{us=Us,ns=Ns} = get_anno(Arg), + A = A0#a{us=del_element(V#c_var.name, Us), + ns=add_element(V#c_var.name, Ns)}, + Le1 = Le0#iset{anno=A,arg=Arg}, + New = union(New0, A#a.ns), + {Les1,Ks,St2} = uexprs_iset(Les0, New, Ks0, St1), + {[Le1|Les1],Ks,St2} + end; +uexprs_iset(Les, New, Ks0, St) -> + Ks = known_union(Ks0, New), + uexprs(Les, Ks, St). + +uexpr_need_known(#icall{}) -> false; +uexpr_need_known(#iapply{}) -> false; +uexpr_need_known(#ibinary{}) -> false; +uexpr_need_known(#iprimop{}) -> false; +uexpr_need_known(#c_literal{}) -> false; +uexpr_need_known(Core) -> not is_simple(Core). + %% upat_is_new_var(Pattern, [KnownVar]) -> true|false. %% Test whether the pattern is a single, previously unknown %% variable. -- 2.31.1
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor