Skip to content

Commit

Permalink
Split in_channel and out_channel in binary_rpc. (#992)
Browse files Browse the repository at this point in the history
This improves performance, sadly not optimized by OCaml.
  • Loading branch information
vaivaswatha authored May 24, 2021
1 parent ce0a248 commit 564471f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
7 changes: 7 additions & 0 deletions src/base/Utils.ml
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,10 @@ let int_fold ~init ~(f : 'a -> int -> 'a) n =
recurser acc' (i + 1)
in
recurser init 0

(* Execute f() and print time taken. *)
let ftimer name ~f =
let t = Core.Unix.gettimeofday () in
let res = f () in
Printf.printf "%s,%f\n" name (Core.Unix.gettimeofday () -. t);
res
2 changes: 2 additions & 0 deletions src/base/Utils.mli
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ open Core_kernel
val list_add_unique : equal:('a -> 'a -> bool) -> 'a List.t -> 'a -> 'a List.t

val int_fold : init:'a -> f:('a -> int -> 'a) -> int -> 'a

val ftimer : string -> f:(unit -> 'a) -> 'a
5 changes: 2 additions & 3 deletions src/eval/StateIPCClient.ml
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,8 @@ let binary_rpc ~socket_addr (call : Rpc.call) : Rpc.response M.t =
Unix.socket ~domain:Unix.PF_UNIX ~kind:Unix.SOCK_STREAM ~protocol:0 ()
in
Unix.connect socket ~addr:(Unix.ADDR_UNIX socket_addr);
let ic, oc =
(Unix.in_channel_of_descr socket, Unix.out_channel_of_descr socket)
in
let ic = Unix.in_channel_of_descr socket in
let oc = Unix.out_channel_of_descr socket in
let msg_buf = Jsonrpc.string_of_call ~version:Jsonrpc.V2 call in
DebugMessage.plog (Printf.sprintf "Sending: %s\n" msg_buf);
(* Send data to the socket. *)
Expand Down

0 comments on commit 564471f

Please sign in to comment.