Преглед на файлове

delay IO.input creation, add per-chunk timer

Simon Krajewski преди 1 година
родител
ревизия
8e784fbbc0
променени са 4 файла, в които са добавени 15 реда и са изтрити 11 реда
  1. 3 5
      src/compiler/hxb/hxbLib.ml
  2. 6 1
      src/compiler/hxb/hxbReader.ml
  3. 1 1
      src/context/common.ml
  4. 5 4
      src/typing/typeloadModule.ml

+ 3 - 5
src/compiler/hxb/hxbLib.ml

@@ -30,17 +30,15 @@ class hxb_library file_path = object(self)
 			close();
 		end
 
-	method load_module (target : string) (path : path) =
+	method get_bytes (target : string) (path : path) =
 		try
-			(* HXB_TODO: See if we can bucket by target a bit nicer. *)
 			let path = (target :: fst path,snd path) in
 			let (filename,entry) = Hashtbl.find modules path in
-			let close = Timer.timer ["hxblib";"load_module"] in
+			let close = Timer.timer ["hxblib";"get bytes"] in
 			let zip = Lazy.force zip in
 			let data = Zip.read_entry zip entry in
-			let input = IO.input_string data in
 			close();
-			Some input
+			Some (Bytes.unsafe_of_string data)
 		with Not_found ->
 			None
 

+ 6 - 1
src/compiler/hxb/hxbReader.ml

@@ -1777,7 +1777,7 @@ class hxb_reader
 		let size = Int32.to_int self#read_i32 in
 		(name,size)
 
-	method private read_chunk_data (kind : chunk_kind) =
+	method private read_chunk_data' (kind : chunk_kind) =
 		match kind with
 		| STR ->
 			string_pool <- self#read_string_pool;
@@ -1825,6 +1825,11 @@ class hxb_reader
 		| EOM ->
 			incr stats.modules_fully_restored;
 
+	method private read_chunk_data kind =
+		let close = Timer.timer ["hxb";"read";string_of_chunk_kind kind] in
+		self#read_chunk_data' kind;
+		close()
+
 	method read_chunks (new_api : hxb_reader_api) (chunks : cached_chunks) =
 		fst (self#read_chunks_until new_api chunks EOM)
 

+ 1 - 1
src/context/common.ml

@@ -335,7 +335,7 @@ end
 
 class virtual abstract_hxb_lib = object(self)
 	method virtual load : unit
-	method virtual load_module : string -> path -> IO.input option
+	method virtual get_bytes : string -> path -> bytes option
 	method virtual close : unit
 	method virtual get_file_path : string
 end

+ 5 - 4
src/typing/typeloadModule.ml

@@ -807,8 +807,9 @@ let rec get_reader ctx p =
 	new hxb_reader_api_typeload ctx load_module' p
 
 and load_hxb_module ctx path p =
-	let read file input =
+	let read file bytes =
 		try
+			let input = IO.input_bytes bytes in
 			let read = (get_reader ctx p)#read_hxb input ctx.com.hxb_reader_stats in
 			let m = read MTF in
 			delay ctx PBuildClass (fun () ->
@@ -830,9 +831,9 @@ and load_hxb_module ctx path p =
 	let target = Common.platform_name_macro ctx.com in
 	let rec loop l = match l with
 		| hxb_lib :: l ->
-			begin match hxb_lib#load_module target path with
-				| Some input ->
-					read hxb_lib#get_file_path input
+			begin match hxb_lib#get_bytes target path with
+				| Some bytes ->
+					read hxb_lib#get_file_path bytes
 				| None ->
 					loop l
 			end