From aaf9b43769ba943d0e87e5fc1ba9e82e6dba4fc2 Mon Sep 17 00:00:00 2001 From: Simon Krajewski Date: Wed, 7 Feb 2024 15:08:30 +0100 Subject: [PATCH] [server] share one reader API across whole context 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. --- src/compiler/server.ml | 9 ++++++++- src/context/common.ml | 3 +++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/src/compiler/server.ml b/src/compiler/server.ml index 636c5cfe4ae..98c0855b26d 100644 --- a/src/compiler/server.ml +++ b/src/compiler/server.ml @@ -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 diff --git a/src/context/common.ml b/src/context/common.ml index ffcb5f91d06..503af30ea7f 100644 --- a/src/context/common.ml +++ b/src/context/common.ml @@ -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; } @@ -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 @@ -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;