2 * Copyright (c) 2018, Facebook, Inc.
5 * This source code is licensed under the MIT license found in the
6 * LICENSE fn in the "hack" directory of this source tree.
12 module DepSet
= Typing_deps.DepSet
13 module Dep
= Typing_deps.Dep
16 (workers
: MultiWorker.worker list
option)
20 let naming_table = env
.ServerEnv.naming_table in
21 let start_t = Unix.gettimeofday
() in
22 Hh_logger.log
"Generating hot classes file...";
24 Naming_table.fold
naming_table ~init
:[] ~f
:begin fun path info acc
->
25 match Relative_path.prefix path
with
26 | Relative_path.Root
->
27 List.fold info
.FileInfo.classes ~init
:acc ~f
:(fun acc
(_
,x
) -> x
::acc
)
31 let add_hot_classes acc cids
=
32 List.fold cids ~init
:acc ~f
:begin fun acc cid
->
33 let deps = DepSet.singleton
@@ Dep.make
(Dep.Class cid
) in
34 let deps = Typing_deps.add_all_deps
deps in
35 if DepSet.cardinal
deps > threshold
then cid
::acc
else acc
43 ~merge
:List.rev_append
44 ~next
:(MultiWorker.next workers
classes_in_repo)
48 |> List.sort ~compare
:String.compare
49 |> List.remove_consecutive_duplicates ~equal
:String.equal
53 let comment = List.map
ServerHotClassesDescription.comment string_
in
54 let classes = List.map
classes_to_save string_
in
55 json_to_string ~pretty
:true @@ JSON_Object
[
56 "comment", JSON_Array
comment;
57 "threshold", int_ threshold
;
58 "classes", JSON_Array
classes;
61 let result = ServerHotClassesDescription.postprocess
(result ^
"\n") in
63 Hh_logger.log_duration
"Done generating hot classes file" start_t in