Skip to content

Commit 75d19e6

Browse files
authored
Merge pull request #4182 from BuckleScript/refactor
various tricks to reduce the cost of loading large data upfront
2 parents b47f9f1 + 13728cb commit 75d19e6

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

59 files changed

+780886
-785799
lines changed

.gitignore

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -140,4 +140,5 @@ native/
140140
vendor/ocaml
141141
jscomp/.lsp
142142
.vscode/launch.json
143-
tracing*.json
143+
tracing*.json
144+
darwin/bsc

.vscode/tasks.json

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,31 @@
5252
}
5353
},
5454
{
55-
"label": "check unused",
55+
"label": "check unused bsc",
5656
"command" : "node",
5757
"options": {
5858
"cwd": "${workspaceRoot}/lib"
5959
},
6060
"args": [
61-
"../scripts/checkUnused.js"
61+
"../scripts/checkUnused.js",
62+
"whole_compiler"
63+
],
64+
"problemMatcher" :{
65+
"base": "$ocamlc",
66+
"fileLocation" :
67+
"autoDetect",
68+
"owner": "globalUnused"
69+
}
70+
},
71+
{
72+
"label": "check unused bsb_helper",
73+
"command" : "node",
74+
"options": {
75+
"cwd": "${workspaceRoot}/lib"
76+
},
77+
"args": [
78+
"../scripts/checkUnused.js" ,
79+
"bsb_helper"
6280
],
6381
"problemMatcher" :{
6482
"base": "$ocamlc",

jscomp/bsb/bsb_parse_sources.ml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -238,11 +238,11 @@ let prune_staled_bs_js_files
238238
let lazy cmd = bs_cmt_post_process_cmd in
239239

240240
if cmd <> "" then
241-
Ext_pervasives.try_it (fun _ ->
241+
(try ignore (
242242
Sys.command (
243243
cmd ^
244244
" -cmt-rm " ^ filepath)
245-
)
245+
: int ) with _ -> ())
246246
| Cmj _ ->
247247
(* remove .bs.js *)
248248
if context.bs_suffix then
@@ -492,13 +492,13 @@ let clean_re_js root =
492492
| None -> Set_string.empty
493493
in
494494
Ext_option.iter (Map_string.find_opt map Bsb_build_schemas.sources) begin fun config ->
495-
Ext_pervasives.try_it (fun () ->
495+
try (
496496
walk_sources { root ;
497497
traverse = true;
498498
cwd = Filename.current_dir_name;
499499
ignored_dirs
500500
} config
501-
)
501+
) with _ -> ()
502502
end
503503
| _ -> ()
504504
| exception _ -> ()

jscomp/common/js_config.ml

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,6 @@ let no_version_header = ref false
5252

5353
let cross_module_inline = ref false
5454

55-
let get_cross_module_inline () = !cross_module_inline
56-
(* let set_cross_module_inline b =
57-
cross_module_inline := b *)
5855

5956

6057
let diagnose = ref false

jscomp/common/js_config.mli

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,6 @@ val get_package_name : unit -> string option *)
4848

4949
(** cross module inline option *)
5050
val cross_module_inline : bool ref
51-
(* val set_cross_module_inline : bool -> unit *)
52-
val get_cross_module_inline : unit -> bool
5351

5452
(** diagnose option *)
5553
val diagnose : bool ref

jscomp/core/bs_cmi_load.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,26 +22,32 @@
2222
* along with this program; if not, write to the Free Software
2323
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *)
2424

25-
#if BS_RELEASE_BUILD then
25+
#if
26+
BS_RELEASE_BUILD
27+
(*true *)
28+
then
2629

2730
let load_cmi ~unit_name : Env.Persistent_signature.t option =
2831
match Config_util.find_opt (unit_name ^".cmi") with
2932
| Some filename -> Some {filename; cmi = Cmi_format.read_cmi filename}
3033
| None ->
3134
if !Js_config.no_stdlib then None
3235
else
33-
match Ext_string_array.find_sorted_assoc Builtin_cmi_datasets.module_sets_cmi unit_name with
36+
match Ext_string_array.find_sorted Builtin_cmi_datasets.module_names unit_name with
3437
| Some cmi ->
3538
if Js_config.get_diagnose () then
3639
Format.fprintf Format.err_formatter ">Cmi: %s@." unit_name;
37-
let lazy cmi = cmi in
40+
let cmi : Cmi_format.cmi_infos =
41+
Marshal.from_string
42+
Builtin_cmi_datasets.module_data.(cmi) 0 in
3843
if Js_config.get_diagnose () then
3944
Format.fprintf Format.err_formatter "<Cmi: %s@." unit_name;
4045
Some {filename = Sys.executable_name ;
4146
cmi }
4247
| None -> None
4348

44-
let check () =
49+
let check () = ()
50+
(*
4551
Ext_array.iter
4652
Builtin_cmi_datasets.module_sets_cmi
4753
(fun (name,l) ->
@@ -60,7 +66,7 @@ let check () =
6066
let cmj = Lazy.force l in
6167
Format.fprintf Format.err_formatter "%b@." cmj.pure;
6268
prerr_endline ("<checking " ^ name);
63-
)
69+
) *)
6470
#else
6571

6672
let check () = ()

jscomp/core/js_cmj_format.ml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ let get_result midVal =
137137
| None ->
138138
midVal
139139
| Some _ ->
140-
if Js_config.get_cross_module_inline () then midVal
140+
if !Js_config.cross_module_inline then midVal
141141
else {midVal with persistent_closed_lambda = None}
142142

143143
let rec binarySearchAux arr lo hi (key : string) =

jscomp/core/js_cmj_format.mli

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ type keyed_cmj_value = {
7070
persistent_closed_lambda : Lam.t option
7171
}
7272

73-
type t = private {
73+
type t = {
7474
values : keyed_cmj_value array ;
7575
pure : bool;
7676
package_spec : Js_packages_info.t ;

jscomp/core/js_cmj_load.ml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,21 @@
3030

3131

3232
let load_builin_unit unit_name : Js_cmj_format.cmj_load_info =
33-
#if BS_RELEASE_BUILD then
34-
match Ext_string_array.find_sorted_assoc
35-
Builtin_cmj_datasets.module_sets
33+
#if
34+
BS_RELEASE_BUILD
35+
(* true *)
36+
then
37+
match Ext_string_array.find_sorted
38+
Builtin_cmj_datasets.module_names
3639
unit_name with
37-
| Some cmj_table
40+
| Some i
3841
->
3942
if Js_config.get_diagnose () then
4043
Format.fprintf Format.err_formatter ">Cmj: %s@." unit_name;
41-
let lazy cmj_table = cmj_table in
44+
let cmj_table : Js_cmj_format.t =
45+
let values, pure = Marshal.from_string Builtin_cmj_datasets.module_data.(i) 0 in
46+
{values; pure; package_spec = Js_packages_info.runtime_package_specs;js_file_kind = Little_js}
47+
in
4248
if Js_config.get_diagnose () then
4349
Format.fprintf Format.err_formatter "<Cmj: %s@." unit_name;
4450
{package_path =

jscomp/core/js_packages_info.ml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,13 @@ type t =
7676
module_systems: package_info list
7777
}
7878

79+
let runtime_package_specs : t = {
80+
name = Pkg_runtime;
81+
module_systems =[
82+
{module_system = Es6; path = "lib/es6"};
83+
{module_system = NodeJS; path = "lib/js"};
84+
]
85+
}
7986
let same_package_by_name (x : t) (y : t) = x.name = y.name
8087

8188
let is_runtime_package (x : t) =

0 commit comments

Comments
 (0)