Skip to content

Commit

Permalink
[hxb] remove writer stats
Browse files Browse the repository at this point in the history
I broke parts of it already anyway.
  • Loading branch information
Simn committed Feb 3, 2024
1 parent 2b0e8ce commit d9fc90a
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 86 deletions.
4 changes: 2 additions & 2 deletions src/compiler/compilationCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,12 @@ class context_cache (index : int) (sign : Digest.t) = object(self)
method find_module_extra path =
try (Hashtbl.find modules path).m_extra with Not_found -> (Hashtbl.find binary_cache path).mc_extra

method cache_module config warn anon_identification hxb_writer_stats path m =
method cache_module config warn anon_identification path m =
match m.m_extra.m_kind with
| MImport ->
Hashtbl.add modules m.m_path m
| _ ->
let writer = HxbWriter.create config warn anon_identification hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification in
HxbWriter.write_module writer m;
let chunks = HxbWriter.get_chunks writer in
Hashtbl.replace binary_cache path {
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/generate.ml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ let export_hxb com config cc platform zip m =
with Not_found ->
let anon_identification = new tanon_identification in
let warn w s p = com.Common.warning w com.warning_options s p in
let writer = HxbWriter.create config warn anon_identification com.hxb_writer_stats in
let writer = HxbWriter.create config warn anon_identification in
HxbWriter.write_module writer m;
let out = IO.output_string () in
HxbWriter.export writer out;
Expand Down
83 changes: 5 additions & 78 deletions src/compiler/hxb/hxbWriter.ml
Original file line number Diff line number Diff line change
Expand Up @@ -45,63 +45,6 @@ let unop_index op flag = match op,flag with
| NegBits,Postfix -> 10
| Spread,Postfix -> 11

type hxb_writer_stats = {
type_instance_kind_writes : int array;
texpr_writes : int array;
type_instance_immediate : int ref;
type_instance_cache_hits : int ref;
type_instance_cache_misses : int ref;
pos_writes_full : int ref;
pos_writes_min : int ref;
pos_writes_max : int ref;
pos_writes_minmax : int ref;
pos_writes_eq : int ref;
chunk_sizes : (string,int ref * int ref) Hashtbl.t;
}

let create_hxb_writer_stats () = {
type_instance_kind_writes = Array.make 255 0;
texpr_writes = Array.make 255 0;
type_instance_immediate = ref 0;
type_instance_cache_hits = ref 0;
type_instance_cache_misses = ref 0;
pos_writes_full = ref 0;
pos_writes_min = ref 0;
pos_writes_max = ref 0;
pos_writes_minmax = ref 0;
pos_writes_eq = ref 0;
chunk_sizes = Hashtbl.create 0;
}

let dump_stats name stats =
let sort_and_filter_array a =
let _,kind_writes = Array.fold_left (fun (index,acc) writes ->
(index + 1,if writes = 0 then acc else (index,writes) :: acc)
) (0,[]) a in
let kind_writes = List.sort (fun (_,writes1) (_,writes2) -> compare writes2 writes1) kind_writes in
List.map (fun (index,writes) -> Printf.sprintf " %3i: %9i" index writes) kind_writes
in
let t_kind_writes = sort_and_filter_array stats.type_instance_kind_writes in
print_endline (Printf.sprintf "hxb_writer stats for %s" name);
print_endline " type instance kind writes:";
List.iter print_endline t_kind_writes;
let texpr_writes = sort_and_filter_array stats.texpr_writes in
print_endline " texpr writes:";
List.iter print_endline texpr_writes;

print_endline " type instance writes:";
print_endline (Printf.sprintf " immediate: %9i" !(stats.type_instance_immediate));
print_endline (Printf.sprintf " cache hits: %9i" !(stats.type_instance_cache_hits));
print_endline (Printf.sprintf " cache miss: %9i" !(stats.type_instance_cache_misses));
print_endline " pos writes:";
print_endline (Printf.sprintf " full: %9i\n min: %9i\n max: %9i\n minmax: %9i\n equal: %9i" !(stats.pos_writes_full) !(stats.pos_writes_min) !(stats.pos_writes_max) !(stats.pos_writes_minmax) !(stats.pos_writes_eq));
(* let chunk_sizes = Hashtbl.fold (fun name (imin,imax) acc -> (name,!imin,!imax) :: acc) stats.chunk_sizes [] in
let chunk_sizes = List.sort (fun (_,imin1,imax1) (_,imin2,imax2) -> compare imax1 imax2) chunk_sizes in
print_endline "chunk sizes:";
List.iter (fun (name,imin,imax) ->
print_endline (Printf.sprintf " %s: %i - %i" name imin imax)
) chunk_sizes *)

module StringHashtbl = Hashtbl.Make(struct
type t = string

Expand Down Expand Up @@ -400,17 +343,10 @@ module Chunk = struct
let write_bool io b =
write_u8 io (if b then 1 else 0)

let export : 'a . hxb_writer_stats -> t -> 'a IO.output -> unit = fun stats io chex ->
let export : 'a . t -> 'a IO.output -> unit = fun io chex ->
let bytes = get_bytes io in
let length = Bytes.length bytes in
write_chunk_prefix io.kind length chex;
(* begin try
let (imin,imax) = Hashtbl.find stats.chunk_sizes io.name in
if length < !imin then imin := length;
if length > !imax then imax := length
with Not_found ->
Hashtbl.add stats.chunk_sizes io.name (ref length,ref length);
end; *)
IO.nwrite chex bytes

let write_string chunk s =
Expand Down Expand Up @@ -438,22 +374,19 @@ end

module PosWriter = struct
type t = {
stats : hxb_writer_stats;
mutable p_file : string;
mutable p_min : int;
mutable p_max : int;
}

let do_write_pos (chunk : Chunk.t) (p : pos) =
(* incr stats.pos_writes_full; *)
Chunk.write_string chunk p.pfile;
Chunk.write_leb128 chunk p.pmin;
Chunk.write_leb128 chunk p.pmax

let create stats chunk p =
let create chunk p =
do_write_pos chunk p;
{
stats;
p_file = p.pfile;
p_min = p.pmin;
p_max = p.pmax;
Expand All @@ -470,27 +403,23 @@ module PosWriter = struct
end else if p.pmin <> pw.p_min then begin
if p.pmax <> pw.p_max then begin
(* pmin and pmax changed *)
(* incr stats.pos_writes_minmax; *)
Chunk.write_u8 chunk (3 + offset);
Chunk.write_leb128 chunk p.pmin;
Chunk.write_leb128 chunk p.pmax;
pw.p_min <- p.pmin;
pw.p_max <- p.pmax;
end else begin
(* pmin changed *)
(* incr stats.pos_writes_min; *)
Chunk.write_u8 chunk (1 + offset);
Chunk.write_leb128 chunk p.pmin;
pw.p_min <- p.pmin;
end
end else if p.pmax <> pw.p_max then begin
(* pmax changed *)
(* incr stats.pos_writes_max; *)
Chunk.write_u8 chunk (2 + offset);
Chunk.write_leb128 chunk p.pmax;
pw.p_max <- p.pmax;
end else begin
(* incr stats.pos_writes_eq; *)
if write_equal then
Chunk.write_u8 chunk offset;
end
Expand All @@ -514,7 +443,6 @@ type hxb_writer = {
config : HxbWriterConfig.writer_target_config;
warn : Warning.warning -> string -> Globals.pos -> unit;
anon_id : Type.t Tanon_identification.tanon_identification;
stats : hxb_writer_stats;
mutable current_module : module_def;
chunks : Chunk.t DynArray.t;
cp : StringPool.t;
Expand Down Expand Up @@ -1794,7 +1722,7 @@ module HxbWriter = struct

and start_texpr writer (p: pos) =
let restore = start_temporary_chunk writer 512 in
let fctx = create_field_writer_context (PosWriter.create writer.stats writer.chunk p) in
let fctx = create_field_writer_context (PosWriter.create writer.chunk p) in
fctx,(fun () ->
restore(fun new_chunk ->
let restore = start_temporary_chunk writer 512 in
Expand Down Expand Up @@ -2287,13 +2215,12 @@ module HxbWriter = struct
l
end

let create config warn anon_id stats =
let create config warn anon_id =
let cp = StringPool.create () in
{
config;
warn;
anon_id;
stats;
current_module = null_module;
chunks = DynArray.create ();
cp = cp;
Expand Down Expand Up @@ -2333,5 +2260,5 @@ let export : 'a . hxb_writer -> 'a IO.output -> unit = fun writer ch ->
write_header ch;
let l = HxbWriter.get_sorted_chunks writer in
List.iter (fun io ->
Chunk.export writer.stats io ch
Chunk.export io ch
) l
3 changes: 0 additions & 3 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,6 @@ type context = {
mutable basic : basic_types;
memory_marker : float array;
hxb_reader_stats : HxbReader.hxb_reader_stats;
hxb_writer_stats : HxbWriter.hxb_writer_stats;
mutable hxb_writer_config : HxbWriterConfig.t option;
}

Expand Down Expand Up @@ -883,7 +882,6 @@ let create compilation_step cs version args display_mode =
report_mode = RMNone;
is_macro_context = false;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
hxb_writer_stats = HxbWriter.create_hxb_writer_stats ();
hxb_writer_config = None;
} in
com
Expand Down Expand Up @@ -935,7 +933,6 @@ let clone com is_macro_context =
overload_cache = new hashtbl_lookup;
module_lut = new module_lut;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
hxb_writer_stats = HxbWriter.create_hxb_writer_stats ();
std = null_class;
empty_class_path = new ClassPath.directory_class_path "" User;
class_paths = new ClassPaths.class_paths;
Expand Down
3 changes: 1 addition & 2 deletions src/context/commonCache.ml
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ let rec cache_context cs com =
(* If we have a signature mismatch, look-up cache for module. Physical equality check is fine as a heueristic. *)
let cc = if m.m_extra.m_sign = sign then cc else cs#get_context m.m_extra.m_sign in
let warn w s p = com.warning w com.warning_options s p in
cc#cache_module config warn anon_identification com.hxb_writer_stats m.m_path m;
cc#cache_module config warn anon_identification m.m_path m;
in
List.iter cache_module com.modules;
begin match com.get_macros() with
Expand All @@ -104,7 +104,6 @@ let rec cache_context cs com =
end;
if Define.raw_defined com.defines "hxb.stats" then begin
HxbReader.dump_stats (platform_name com.platform) com.hxb_reader_stats;
HxbWriter.dump_stats (platform_name com.platform) com.hxb_writer_stats
end

let maybe_add_context_sign cs com desc =
Expand Down

0 comments on commit d9fc90a

Please sign in to comment.