From 289249c89b380d31ac8d1049e7b7373d603f5bc0 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Fri, 22 Jul 2022 12:54:21 +0200 Subject: [PATCH 1/2] irmin-tezos: simplify the way we serialise nodes The awkward order is not necessary anymore since irmin 1.4 and no such order exists in the wild. --- src/irmin-tezos/schema.ml | 19 ++----------------- 1 file changed, 2 insertions(+), 17 deletions(-) diff --git a/src/irmin-tezos/schema.ml b/src/irmin-tezos/schema.ml index 0ecb2b4249..b5fc92fe6f 100644 --- a/src/irmin-tezos/schema.ml +++ b/src/irmin-tezos/schema.ml @@ -76,13 +76,6 @@ struct type entry = string * M.value - (* Irmin 1.4 uses int8 to store filename lengths. - - Irmin 2 use a variable-size encoding for strings; this is using int8 - for strings of size stricly less than 128 (e.g. 2^7) which happen to - be the case for all filenames ever produced by Irmin 1.4. *) - let step_t = Irmin.Type.string - let metadata_t = let some = "\255\000\000\000\000\000\000\000" in let none = "\000\000\000\000\000\000\000\000" in @@ -103,7 +96,7 @@ struct let open Irmin.Type in record "Tree.entry" (fun _ _ _ -> assert false) |+ field "kind" metadata_t metadata_of_entry - |+ field "name" step_t fst + |+ field "name" string fst |+ field "hash" Hash.t hash_of_entry |> sealr @@ -111,15 +104,7 @@ struct Irmin.Type.(list ~len:`Int64 entry_t) let pre_hash_entries = Irmin.Type.(unstage (pre_hash entries_t)) - let compare_entry (x, _) (y, _) = String.compare x y - let step_to_string = Irmin.Type.(unstage (to_bin_string Path.step_t)) - let str_key (k, v) = (step_to_string k, v) - - let pre_hash t = - M.list t - |> List.map str_key - |> List.fast_sort compare_entry - |> pre_hash_entries + let pre_hash t = M.list t |> pre_hash_entries end include M From 430fdbc614f46768871ff7c2bcbc7180023c6190 Mon Sep 17 00:00:00 2001 From: Thomas Gazagnaire Date: Mon, 25 Jul 2022 10:40:09 +0200 Subject: [PATCH 2/2] irmin-tezos: unroll allocation hotspot --- src/irmin-tezos/schema.ml | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/irmin-tezos/schema.ml b/src/irmin-tezos/schema.ml index b5fc92fe6f..20b4697075 100644 --- a/src/irmin-tezos/schema.ml +++ b/src/irmin-tezos/schema.ml @@ -103,8 +103,17 @@ struct let entries_t : entry list Irmin.Type.t = Irmin.Type.(list ~len:`Int64 entry_t) + let pre_hash_entry = Irmin.Type.(unstage (pre_hash entry_t)) let pre_hash_entries = Irmin.Type.(unstage (pre_hash entries_t)) - let pre_hash t = M.list t |> pre_hash_entries + let encode_bin_int64 = Irmin.Type.(unstage (pre_hash int64)) + + let pre_hash t f = + match M.length t with + | 0 -> pre_hash_entries [] f + | 1 -> + encode_bin_int64 1L f; + pre_hash_entry (List.hd (M.list t)) f + | _ -> pre_hash_entries (M.list t) f end include M