Skip to content

Commit

Permalink
[server] share one reader API across whole context
Browse files Browse the repository at this point in the history
I don't see why we would have to recreate this for every module because it only depends on com and cc, and carries no additional state.
  • Loading branch information
Simn committed Feb 7, 2024
1 parent 2fb7155 commit aaf9b43
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
9 changes: 8 additions & 1 deletion src/compiler/server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -564,7 +564,14 @@ and type_module sctx com mpath p =
begin match check_module sctx mpath mc.mc_extra p with
| None ->
let reader = new HxbReader.hxb_reader mpath com.hxb_reader_stats in
let api = (new hxb_reader_api_server com cc :> HxbReaderApi.hxb_reader_api) in
let api = match com.hxb_reader_api with
| Some api ->
api
| None ->
let api = (new hxb_reader_api_server com cc :> HxbReaderApi.hxb_reader_api) in
com.hxb_reader_api <- Some api;
api
in
let f_next chunks until =
let t_hxb = Timer.timer ["server";"module cache";"hxb read"] in
let r = reader#read_chunks_until api chunks until in
Expand Down
3 changes: 3 additions & 0 deletions src/context/common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -419,6 +419,7 @@ type context = {
(* misc *)
mutable basic : basic_types;
memory_marker : float array;
mutable hxb_reader_api : HxbReaderApi.hxb_reader_api option;
hxb_reader_stats : HxbReader.hxb_reader_stats;
mutable hxb_writer_config : HxbWriterConfig.t option;
}
Expand Down Expand Up @@ -844,6 +845,7 @@ let create compilation_step cs version args display_mode =
has_error = false;
report_mode = RMNone;
is_macro_context = false;
hxb_reader_api = None;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
hxb_writer_config = None;
} in
Expand Down Expand Up @@ -896,6 +898,7 @@ let clone com is_macro_context =
overload_cache = new hashtbl_lookup;
module_lut = new module_lut;
fake_modules = Hashtbl.create 0;
hxb_reader_api = None;
hxb_reader_stats = HxbReader.create_hxb_reader_stats ();
std = null_class;
empty_class_path = new ClassPath.directory_class_path "" User;
Expand Down

0 comments on commit aaf9b43

Please sign in to comment.