Optimize attribute loading

Summary:
Optimize attribute loading by caching all attributes read from file in
memory.  This reduces io and allocation rate and raises memory usage.

Reviewed By: cristianoc

Differential Revision: D3321156

fbshipit-source-id: 37bc6bc
master
Josh Berdine 9 years ago committed by Facebook Github Bot 5
parent dbb6d08254
commit 66faedbf15

@ -56,9 +56,17 @@ let store_attributes proc_attributes => {
} }
}; };
let load_attributes proc_name => { let attr_tbl = Procname.Hash.create 16;
let load_attributes proc_name =>
try (Procname.Hash.find attr_tbl proc_name) {
| Not_found =>
let attributes_file = res_dir_attr_filename proc_name; let attributes_file = res_dir_attr_filename proc_name;
Serialization.from_file serializer attributes_file let attr = Serialization.from_file serializer attributes_file;
if (attr != None) {
Procname.Hash.add attr_tbl proc_name attr
};
attr
}; };
@ -97,3 +105,22 @@ let pname_is_cpp_model callee_pname =>
DB.file_is_in_cpp_model file DB.file_is_in_cpp_model file
| None => false | None => false
}; };
let stats () => {
let stats = Procname.Hash.stats attr_tbl;
let {Hashtbl.num_bindings: num_bindings, num_buckets, max_bucket_length} = stats;
let serialized_size = lazy (Marshal.data_size (Marshal.to_bytes attr_tbl []) 0 / 1024);
(
"AttributesTable.attr_tbl",
`Assoc (
[
("num_bindings", `Int num_bindings),
("num_buckets", `Int num_buckets),
("max_bucket_length", `Int max_bucket_length)
]
@ (
Config.developer_mode ? [("serialized_size_kb", `Int (Lazy.force serialized_size))] : []
)
)
)
};

@ -9,11 +9,11 @@
* LICENSE file in the root directory of this source tree. An additional grant * LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory. * of patent rights can be found in the PATENTS file in the same directory.
*/ */
/** Module to manage the table of attributes. */
open! Utils; open! Utils;
/** Module to manage the table of attributes. */
/** Save .attr file for the procedure into the attributes database. */ /** Save .attr file for the procedure into the attributes database. */
let store_attributes: ProcAttributes.t => unit; let store_attributes: ProcAttributes.t => unit;
@ -32,5 +32,8 @@ let find_tenv_from_class_of_proc: Procname.t => option Tenv.t;
/** finding the tenv that corresponds to the class definition. */ /** finding the tenv that corresponds to the class definition. */
let get_correct_type_from_objc_class_name: Mangled.t => option Sil.typ; let get_correct_type_from_objc_class_name: Mangled.t => option Sil.typ;
/** Returns true if the method is defined as a C++ model */ /** Returns true if the method is defined as a C++ model */
let pname_is_cpp_model: Procname.t => bool; let pname_is_cpp_model: Procname.t => bool;
let stats: unit => (string, Yojson.json);

@ -25,7 +25,7 @@ let register_report_at_exit file =
let exit_timeofday = Unix.gettimeofday () in let exit_timeofday = Unix.gettimeofday () in
let exit_times = Unix.times () in let exit_times = Unix.times () in
let stats = let stats =
`Assoc [ `Assoc ([
("rtime", `Float (exit_timeofday -. initial_timeofday)) ; ("rtime", `Float (exit_timeofday -. initial_timeofday)) ;
("utime", `Float (exit_times.tms_utime -. initial_times.tms_utime)) ; ("utime", `Float (exit_times.tms_utime -. initial_times.tms_utime)) ;
("stime", `Float (exit_times.tms_stime -. initial_times.tms_stime)) ; ("stime", `Float (exit_times.tms_stime -. initial_times.tms_stime)) ;
@ -40,8 +40,8 @@ let register_report_at_exit file =
("compactions", `Int gc_stats.compactions) ; ("compactions", `Int gc_stats.compactions) ;
("top_heap_gb", `Float (words_to_gb (float_of_int gc_stats.top_heap_words))) ; ("top_heap_gb", `Float (words_to_gb (float_of_int gc_stats.top_heap_words))) ;
("stack_kb", `Float (words_to_kb (float_of_int gc_stats.stack_size))) ; ("stack_kb", `Float (words_to_kb (float_of_int gc_stats.stack_size))) ;
("minor_heap_kb", `Float (words_to_kb (float_of_int gc_ctrl.minor_heap_size))) ; ("minor_heap_kb", `Float (words_to_kb (float_of_int gc_ctrl.minor_heap_size)))
] in ] @ [AttributesTable.stats ()]) in
try try
let stats_oc = open_out file in let stats_oc = open_out file in
Yojson.pretty_to_channel stats_oc stats ; Yojson.pretty_to_channel stats_oc stats ;

Loading…
Cancel
Save