From d7d0fdbbbc5d7f34f95a248db179c0958b96ece9 Mon Sep 17 00:00:00 2001 From: Pavlo Khrystenko Date: Thu, 18 May 2023 15:53:12 +0200 Subject: [PATCH] Snoop: add group to proto_alpha/lib_benchmarks_proto --- src/lib_benchmark/benchmark.ml | 14 ++++ .../lib_benchmarks_proto/apply_benchmarks.ml | 7 +- .../lib_benchmarks_proto/benchmarks_proto.ml | 24 +++++- .../lib_benchmarks_proto/benchmarks_proto.mli | 32 +++++--- .../lib_benchmarks_proto/cache_benchmarks.ml | 6 +- .../carbonated_map_benchmarks.ml | 81 +++++++------------ .../global_constants_storage_benchmarks.ml | 14 +++- .../interpreter_benchmarks.ml | 1 + .../sc_rollup_benchmarks.ml | 6 ++ .../script_repr_benchmarks.ml | 33 ++++---- .../script_typed_ir_size_benchmarks.ml | 63 ++++++--------- .../skip_list_benchmarks.ml | 5 ++ .../storage_benchmarks.ml | 37 ++++----- .../lib_benchmarks_proto/ticket_benchmarks.ml | 78 +++++++----------- .../translator_benchmarks.ml | 60 +++++--------- tezt/snoop/perform_inference.ml | 4 +- 16 files changed, 226 insertions(+), 239 deletions(-) diff --git a/src/lib_benchmark/benchmark.ml b/src/lib_benchmark/benchmark.ml index ae7881b7977e..71ddd928b160 100644 --- a/src/lib_benchmark/benchmark.ml +++ b/src/lib_benchmark/benchmark.ml @@ -68,6 +68,20 @@ module type S = sig include Generator.S with type config := config and type workload := workload end +(** Some benchmarks depend on others, and some are for generic parameters that + most benchmarks depend on. We need this information in order to correctly + infer the values of parameters after a benchmark run; the user provides it + with a group. + + * [Standalone]: benchmarks that don't depend on others (except generic + ones). This is the value to use if you're not sure whether you should + group your benchmark. + * [Group]: benchmarks that belong to the given inference group. Note that + setting a benchmark with a group that is referenced only in this benchmark + will produce the same inference results as with [Standalone]. + * [Generic]: for generic parameters only. *) +type group = Standalone | Group of string | Generic + type t = (module S) type ('cfg, 'workload) poly = diff --git a/src/proto_alpha/lib_benchmarks_proto/apply_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/apply_benchmarks.ml index b770478b8518..46bc24087845 100644 --- a/src/proto_alpha/lib_benchmarks_proto/apply_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/apply_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,8 +25,9 @@ (*****************************************************************************) open Tezos_benchmark +open Benchmarks_proto -let ns = Namespace.make Registration_helpers.ns "apply" +let ns = Namespace.make Registration.ns "apply" let fv s = Free_variable.of_namespace (ns s) @@ -66,6 +68,8 @@ module Take_fees_benchmark = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["apply"] type config = unit @@ -87,7 +91,6 @@ module Take_fees_benchmark = struct Sparse_vec.String.of_list [("batch_length", float_of_int batch_length)] let model = - let open Benchmarks_proto in Model.make ~conv:(fun {batch_length} -> (batch_length, ())) ~model:Model.affine diff --git a/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.ml b/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.ml index 29a3ef9350b7..50b2f57afeed 100644 --- a/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.ml +++ b/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,6 +27,8 @@ module Benchmark_base = Benchmark module Benchmark = struct + type group = Benchmark_base.group = Standalone | Group of string | Generic + module type S = sig val name : Namespace.t @@ -33,6 +36,10 @@ module Benchmark = struct val module_filename : string + val generated_code_destination : string option + + val group : group + val tags : string list type config @@ -49,8 +56,6 @@ module Benchmark = struct val model : name:Namespace.t -> workload Model.t - val generated_code_destination : string option - val create_benchmark : rng_state:Random.State.t -> config -> workload Generator.benchmark end @@ -74,7 +79,13 @@ module Registration = struct Bench.generated_code_destination let models = - [(Namespace.(cons name "model" |> to_string), Bench.model ~name)] + [ + ( (match Bench.group with + | Generic -> "*" + | Group g -> g + | Standalone -> Namespace.(cons Bench.name "model" |> to_string)), + Bench.model ~name ); + ] let create_benchmarks ~rng_state ~bench_num config = List.repeat bench_num (fun () -> @@ -86,8 +97,15 @@ end module Model = struct include Model + type 'workload t = 'workload Model.t + let make ~name ~conv ~model = make ~conv ~model:(model name) + let unknown_const1 ?const name = + let ns s = Free_variable.of_namespace (Namespace.cons name s) in + let const = Option.value ~default:(ns "const") const in + unknown_const1 ~name ~const + let affine ?intercept ?coeff name = let ns s = Free_variable.of_namespace (Namespace.cons name s) in let intercept = Option.value ~default:(ns "intercept") intercept in diff --git a/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.mli b/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.mli index 7e16177b7d6a..9d57ffb7429f 100644 --- a/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.mli +++ b/src/proto_alpha/lib_benchmarks_proto/benchmarks_proto.mli @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2023 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -26,8 +27,10 @@ module Benchmark_base = Benchmark module Benchmark : sig + type group = Benchmark_base.group = Standalone | Group of string | Generic + (** The module type of benchmarks, a simplification of {!Benchmark.S} used by - [registration_simple] below. *) + [Registration.register] below. *) module type S = sig (** Name of the benchmark *) val name : Namespace.t @@ -38,6 +41,17 @@ module Benchmark : sig (** Filename of the benchmark module *) val module_filename : string + (** Generated code file location, automatically prefix by + "src/proto_alpha/lib_protocol/" + and suffixed by + "_costs_generated.ml". + It is optional in case some benchmarks don't output code, but are used + for verification purposes. *) + val generated_code_destination : string option + + (** Inference group of the benchmark *) + val group : group + (** Tags of the benchmark *) val tags : string list @@ -62,17 +76,9 @@ module Benchmark : sig (** Cost model *) val model : name:Namespace.t -> workload Model.t - (** Generated code file location, automatically prefix by - "src/proto_alpha/lib_protocol/" - and suffixed by - "_costs_generated.ml". - It is optional in case some benchmarks don't output code, but are used - for verification purposes. *) - val generated_code_destination : string option - (** Creates a benchmark, ready to be run. - The benchmarks are thunked to prevent evaluating the workload until - needed. *) + The benchmarks are thunked to prevent evaluating the workload until + needed. *) val create_benchmark : rng_state:Random.State.t -> config -> workload Generator.benchmark end @@ -91,12 +97,16 @@ end module Model : sig open Model + type 'workload t = 'workload Model.t + val make : name:Namespace.t -> conv:('a -> 'b) -> model:(Namespace.t -> 'b model) -> 'a t + val unknown_const1 : ?const:Free_variable.t -> Namespace.t -> unit model + val affine : ?intercept:Free_variable.t -> ?coeff:Free_variable.t -> diff --git a/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml index b2bb25523d28..c6251acd926f 100644 --- a/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/cache_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,6 +25,7 @@ (*****************************************************************************) open Protocol +open Benchmarks_proto let ns = Namespace.make Registration_helpers.ns "cache" @@ -137,6 +139,8 @@ module Cache_update_benchmark : Benchmarks_proto.Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + (** It is expected that cache keys are non-adversarial, ie do not share a long common prefix. This is the case for [Script_cache], for which the keys are B58-encoded contract hashes. @@ -146,7 +150,7 @@ module Cache_update_benchmark : Benchmarks_proto.Benchmark.S = struct We therefore do not take into account the length of the key in the model. *) let model = let affine_logn name = - let open Model in + let open Tezos_benchmark.Model in let param_name param = Free_variable.of_namespace (Namespace.cons name param) in diff --git a/src/proto_alpha/lib_benchmarks_proto/carbonated_map_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/carbonated_map_benchmarks.ml index f1862d9c4106..bcfc855f149b 100644 --- a/src/proto_alpha/lib_benchmarks_proto/carbonated_map_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/carbonated_map_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,11 +25,14 @@ (*****************************************************************************) open Tezos_benchmark +open Benchmarks_proto -let ns = Namespace.make Registration_helpers.ns "carbonated_map" +let ns = Namespace.make Registration.ns "carbonated_map" let fv s = Free_variable.of_namespace (ns s) +let group = Benchmark.Group "carbonated_map" + let make_context ~rng_state = match Lwt_main.run @@ Execution_context.make ~rng_state with | Ok (ctxt, _) -> ctxt @@ -51,6 +55,8 @@ module Config_and_workload = struct let tags = ["carbonated_map"] + let group = group + let workload_encoding = config_encoding let workload_to_vector {size} = @@ -81,18 +87,15 @@ module Fold_benchmark : Benchmark.S = struct let info = "Carbonated map to list" - let fold_model = + let model = Model.make ~conv:(fun {size} -> (size, ())) ~model: (Model.affine - ~name ~intercept:(fv "fold_const") ~coeff:(fv "fold_cost_per_item")) - let models = [("carbonated_map", fold_model)] - - let benchmark rng_state config () = + let create_benchmark ~rng_state config = let module M = Carbonated_map.Make (Alpha_context_gas) (Int) in let _, list = let sampler rng_state = @@ -122,9 +125,6 @@ module Fold_benchmark : Benchmark.S = struct ignore @@ M.fold_e ctxt (fun ctxt _ _ _ -> ok ((), ctxt)) () map in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end (** Module type that consists of a comparable type along with a sampler @@ -169,23 +169,18 @@ module Make (CS : COMPARABLE_SAMPLER) = struct let generated_code_destination = None - let models = - [ - ( "carbonated_map", - Model.make - ~conv:(fun () -> ()) - ~model: - (Model.unknown_const1 ~name ~const:(compare_var CS.type_name)) ); - ] + let group = group + + let model = + Model.make + ~conv:(fun () -> ()) + ~model:(Model.unknown_const1 ~const:(compare_var CS.type_name)) - let benchmark rng_state _conf () = + let create_benchmark ~rng_state _conf = let key = CS.sampler rng_state in let workload = () in let closure () = ignore (CS.compare key key) in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end module Find = struct @@ -211,7 +206,13 @@ module Make (CS : COMPARABLE_SAMPLER) = struct [intercept + (log2 size * compare_cost) + (log2 size * traversal_overhead)] *) - let find_model ~name ~intercept ~traverse_overhead = + let find_model ?intercept ?traverse_overhead name = + let open Tezos_benchmark in + let ns s = Free_variable.of_namespace (Namespace.cons name s) in + let traverse_overhead = + Option.value ~default:(ns "traverse_overhead") traverse_overhead + in + let intercept = Option.value ~default:(ns "intercept") intercept in let module M = struct type arg_type = int * unit @@ -234,19 +235,9 @@ module Make (CS : COMPARABLE_SAMPLER) = struct end in (module M : Model.Model_impl with type arg_type = int * unit) - let models = - [ - ( "carbonated_map", - Model.make - ~conv:(fun {size} -> (size, ())) - ~model: - (find_model - ~name - ~intercept:(fv "intercept") - ~traverse_overhead:(fv "traversal_overhead")) ); - ] - - let benchmark rng_state (config : config) () = + let model = Model.make ~conv:(fun {size} -> (size, ())) ~model:find_model + + let create_benchmark ~rng_state (config : config) = let _, list = let sampler rng_state = (CS.sampler rng_state, ()) in Structure_samplers.list @@ -272,9 +263,6 @@ module Make (CS : COMPARABLE_SAMPLER) = struct let workload = {size = M.size map} in let closure () = ignore @@ M.find ctxt key map in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end module Find_intercept = struct @@ -310,24 +298,17 @@ module Make (CS : COMPARABLE_SAMPLER) = struct let generated_code_destination = None - let models = - [ - ( "carbonated_map", - Model.make - ~conv:(fun () -> ()) - ~model:(Model.unknown_const1 ~name ~const:(fv "intercept")) ); - ] + let group = group - let benchmark rng_state (_config : config) () = + let model = Model.make ~conv:(fun () -> ()) ~model:Model.unknown_const1 + + let create_benchmark ~rng_state (_config : config) = let ctxt = make_context ~rng_state in let map = M.empty in let key = CS.sampler rng_state in let workload = () in let closure () = ignore @@ M.find ctxt key map in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end end @@ -346,7 +327,7 @@ end module Benchmarks_int = Make (Int) let () = - let open Registration_helpers in + let open Registration in register (module Fold_benchmark) ; register (module Benchmarks_int.Compare) ; register (module Benchmarks_int.Find) ; diff --git a/src/proto_alpha/lib_benchmarks_proto/global_constants_storage_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/global_constants_storage_benchmarks.ml index de76c39c8cf9..22731fcfeded 100644 --- a/src/proto_alpha/lib_benchmarks_proto/global_constants_storage_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/global_constants_storage_benchmarks.ml @@ -1,7 +1,7 @@ (*****************************************************************************) (* *) (* Open Source License *) -(* Copyright (c) 2021 Marigold *) +(* Copyright (c) 2022-2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -301,6 +301,8 @@ module Set_add : Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit @@ -346,6 +348,8 @@ module Set_elements : Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit @@ -393,6 +397,8 @@ module Script_expr_hash_of_b58check_opt : Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit @@ -453,6 +459,8 @@ struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit @@ -527,6 +535,8 @@ module Global_constants_storage_expand_models = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit @@ -592,6 +602,8 @@ module Global_constants_storage_expand_models = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["global_constants"] type config = unit diff --git a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml index 2a860ca92a76..164ea3bc9eb9 100644 --- a/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/interpreter_benchmarks.ml @@ -3,6 +3,7 @@ (* Open Source License *) (* Copyright (c) 2021-2022 Nomadic Labs *) (* Copyright (c) 2022 DaiLambda, Inc. *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) diff --git a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml index 544271e08785..625d2f9ab167 100644 --- a/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/sc_rollup_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -292,6 +293,8 @@ module Sc_rollup_verify_output_proof_benchmark = struct let generated_code_destination = None + let group = Benchmarks_proto.Benchmark.Standalone + let tags = ["sc_rollup"] type config = { @@ -490,6 +493,7 @@ end The inferred cost model is [c1 + c2 * proof_length]. *) module Sc_rollup_deserialize_output_proof_benchmark = struct open Pvm_state_generator + open Benchmarks_proto module Full_Wasm = Sc_rollup_wasm.V2_0_0.Make (Environment.Wasm_2_0_0.Make) (Wasm_context) @@ -503,6 +507,8 @@ module Sc_rollup_deserialize_output_proof_benchmark = struct let generated_code_destination = None + let group = Benchmark.Standalone + let tags = ["sc_rollup"] type config = { diff --git a/src/proto_alpha/lib_benchmarks_proto/script_repr_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/script_repr_benchmarks.ml index 0c57d0d9b523..b6c709643816 100644 --- a/src/proto_alpha/lib_benchmarks_proto/script_repr_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/script_repr_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,8 +25,9 @@ (*****************************************************************************) open Protocol +open Benchmarks_proto -let ns = Namespace.make Registration_helpers.ns "script_repr" +let ns = Namespace.make Registration.ns "script_repr" let fv s = Free_variable.of_namespace (ns s) @@ -84,12 +86,13 @@ module Micheline_nodes_benchmark : Benchmark.S = struct let generated_code_destination = None - let size_based_model = + let group = Benchmark.Group "size_translator_model" + + let model = Model.make ~conv:(function {micheline_nodes} -> (micheline_nodes, ())) ~model: (Model.affine - ~name ~intercept: (fv (Format.asprintf "%s_const" (Namespace.basename name))) ~coeff: @@ -98,23 +101,18 @@ module Micheline_nodes_benchmark : Benchmark.S = struct "%s_ns_per_node_coeff" (Namespace.basename name)))) - let models = [("size_translator_model", size_based_model)] - let micheline_nodes_benchmark node = let nodes = Script_repr.micheline_nodes node in let workload = {micheline_nodes = nodes} in let closure () = ignore (Script_repr.micheline_nodes node) in Generator.Plain {workload; closure} - let make_bench rng_state _cfg () = + let create_benchmark ~rng_state _cfg = let term = Sampler.sample rng_state in micheline_nodes_benchmark term - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) end -let () = Registration_helpers.register (module Micheline_nodes_benchmark) +let () = Registration.register (module Micheline_nodes_benchmark) module Script_repr_strip_annotations : Benchmark.S = struct include Script_repr_shared_config @@ -127,22 +125,19 @@ module Script_repr_strip_annotations : Benchmark.S = struct let generated_code_destination = None - let strip_annotations_model = + let group = Benchmark.Group "strip_annotations_model" + + let model = Model.( make ~conv:(fun {micheline_nodes} -> (micheline_nodes, ())) - ~model:(linear ~name ~coeff:(fv "nodes"))) - - let models = [("strip_annotations_model", strip_annotations_model)] + ~model:(linear ~coeff:(fv "nodes"))) - let create_benchmark rng_state () = + let create_benchmark ~rng_state () = let node = Sampler.sample rng_state in let closure () = ignore @@ Script_repr.strip_annotations node in let micheline_nodes = Script_repr.micheline_nodes node in Generator.Plain {workload = {micheline_nodes}; closure} - - let create_benchmarks ~rng_state ~bench_num _cfg = - List.repeat bench_num (create_benchmark rng_state) end -let () = Registration_helpers.register (module Script_repr_strip_annotations) +let () = Registration.register (module Script_repr_strip_annotations) diff --git a/src/proto_alpha/lib_benchmarks_proto/script_typed_ir_size_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/script_typed_ir_size_benchmarks.ml index 5553a9c2992d..1c9aca18bbfb 100644 --- a/src/proto_alpha/lib_benchmarks_proto/script_typed_ir_size_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/script_typed_ir_size_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,8 +25,9 @@ (*****************************************************************************) open Protocol +open Benchmarks_proto -let ns = Namespace.make Registration_helpers.ns "script_typed_ir_size" +let ns = Namespace.make Registration.ns "script_typed_ir_size" let fv s = Free_variable.of_namespace (ns s) @@ -52,28 +54,24 @@ module Size_benchmarks_shared_config = struct let tags = [Tags.translator] - let size_based_model name = - let intercept_variable = fv (Format.asprintf "%s_const" name) in - let coeff_variable = fv (Format.asprintf "%s_size_coeff" name) in + let size_based_model ~name = + let basename = Namespace.basename name in + let intercept_variable = fv (Format.asprintf "%s_const" basename) in + let coeff_variable = fv (Format.asprintf "%s_size_coeff" basename) in Model.make + ~name ~conv:(function {size} -> (size, ())) - ~model: - (Model.affine - ~name:(ns name) - ~intercept:intercept_variable - ~coeff:coeff_variable) + ~model:(Model.affine ~intercept:intercept_variable ~coeff:coeff_variable) end -module Value_size_benchmark : sig - include Tezos_benchmark.Benchmark.S - - val size_based_model : string -> workload Model.t -end = struct +module Value_size_benchmark : Tezos_benchmark.Benchmark.S = struct include Size_benchmarks_shared_config let name = ns "VALUE_SIZE" - let models = [(model_name, size_based_model (Namespace.basename name))] + let models = + let model = size_based_model ~name in + [(model_name, model)] let info = "Benchmarking Script_typed_ir_size.value_size" @@ -138,7 +136,7 @@ let () = Registration_helpers.register (module Value_size_benchmark) (** Benchmarking {!Script_typed_ir_size.ty_size}. *) -module Type_size_benchmark : Tezos_benchmark.Benchmark.S = struct +module Type_size_benchmark : Benchmark.S = struct include Size_benchmarks_shared_config type config = unit @@ -156,7 +154,9 @@ module Type_size_benchmark : Tezos_benchmark.Benchmark.S = struct let generated_code_destination = None - let models = [(model_name, size_based_model (Namespace.basename name))] + let group = Benchmark.Group model_name + + let model = size_based_model let type_size_benchmark (Script_typed_ir.Ex_ty ty) = let open Script_typed_ir_size.Internal_for_tests in @@ -166,7 +166,7 @@ module Type_size_benchmark : Tezos_benchmark.Benchmark.S = struct let closure () = ignore (ty_size ty) in Generator.Plain {workload; closure} - let make_bench rng_state _cfg () = + let create_benchmark ~rng_state _cfg = (* The [size] here is a parameter to the random sampler and does not match the [size] returned by [type_size]. *) let size = @@ -176,25 +176,18 @@ module Type_size_benchmark : Tezos_benchmark.Benchmark.S = struct Michelson_generation.Samplers.Random_type.m_type ~size rng_state in type_size_benchmark ex_ty - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) end -let () = Registration_helpers.register (module Type_size_benchmark) +let () = Registration.register (module Type_size_benchmark) (** Benchmarking {!Script_typed_ir_size.kinstr_size}. *) -module Kinstr_size_benchmark : sig - include Tezos_benchmark.Benchmark.S - - val size_based_model : string -> workload Model.t -end = struct +module Kinstr_size_benchmark : Tezos_benchmark.Benchmark.S = struct include Size_benchmarks_shared_config let name = ns "KINSTR_SIZE" - let models = [(model_name, size_based_model (Namespace.basename name))] + let models = [(model_name, size_based_model ~name)] let info = "Benchmarking Script_typed_ir_size.kinstr_size" @@ -283,12 +276,13 @@ module Node_size_benchmark : Benchmark.S = struct let generated_code_destination = None - let size_based_model = + let group = Benchmark.Group model_name + + let model = Model.make ~conv:(function {micheline_nodes} -> (micheline_nodes, ())) ~model: (Model.affine - ~name ~intercept: (fv (Format.asprintf "%s_const" (Namespace.basename name))) ~coeff: @@ -297,8 +291,6 @@ module Node_size_benchmark : Benchmark.S = struct "%s_ns_per_node_coeff" (Namespace.basename name)))) - let models = [(model_name, size_based_model)] - let micheline_nodes_benchmark node = let open Cache_memory_helpers in let nodes = Nodes.to_int @@ fst @@ node_size node in @@ -306,12 +298,9 @@ module Node_size_benchmark : Benchmark.S = struct let closure () = ignore (Script_typed_ir_size.node_size node) in Generator.Plain {workload; closure} - let make_bench rng_state _cfg () = + let create_benchmark ~rng_state _cfg = let term = Script_repr_benchmarks.Sampler.sample rng_state in micheline_nodes_benchmark term - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) end -let () = Registration_helpers.register (module Node_size_benchmark) +let () = Registration.register (module Node_size_benchmark) diff --git a/src/proto_alpha/lib_benchmarks_proto/skip_list_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/skip_list_benchmarks.ml index ee4592c769e1..09d97e298fdc 100644 --- a/src/proto_alpha/lib_benchmarks_proto/skip_list_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/skip_list_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -56,6 +57,8 @@ module Next : Benchmark.S = struct let module_filename = __FILE__ + let group = Benchmark.Standalone + let config_encoding = let open Data_encoding in conv (fun {max_items} -> max_items) (fun max_items -> {max_items}) int31 @@ -108,6 +111,8 @@ module Hash_cell : Benchmark.S = struct let module_filename = __FILE__ + let group = Benchmark.Standalone + include Skip_list module Hash = Sc_rollup_inbox_repr.Hash diff --git a/src/proto_alpha/lib_benchmarks_proto/storage_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/storage_benchmarks.ml index e36e82fecbd5..386e254cb9f4 100644 --- a/src/proto_alpha/lib_benchmarks_proto/storage_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/storage_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -31,6 +32,7 @@ *) open Tezos_benchmark +open Benchmarks_proto open Storage_functors open Protocol @@ -170,17 +172,15 @@ module List_key_values_benchmark_boilerplate = struct let workload_to_vector {size} = Sparse_vec.String.of_list [("size", float_of_int size)] - let models = - [ - ( "list_key_values", - Model.make - ~conv:(fun {size} -> (size, ())) - ~model: - (Model.affine - ~name - ~intercept:(fv "list_key_values_intercept") - ~coeff:(fv "list_key_values_step")) ); - ] + let group = Benchmark.Group "list_key_values" + + let model = + Model.make + ~conv:(fun {size} -> (size, ())) + ~model: + (Model.affine + ~intercept:(fv "list_key_values_intercept") + ~coeff:(fv "list_key_values_step")) end module List_key_values_benchmark = struct @@ -190,7 +190,7 @@ module List_key_values_benchmark = struct let generated_code_destination = None - let benchmark rng_state {max_size} () = + let create_benchmark ~rng_state {max_size} = let wrap m = m >|= Environment.wrap_tzresult in let size = Base_samplers.sample_in_interval @@ -218,9 +218,6 @@ module List_key_values_benchmark = struct Table.list_key_values ~length:0 ctxt |> Lwt_main.run |> ignore in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end module List_key_values_benchmark_intercept = struct @@ -232,7 +229,7 @@ module List_key_values_benchmark_intercept = struct let generated_code_destination = None - let benchmark _rng_state _config () = + let create_benchmark ~rng_state:_ _config = let ctxt = match Lwt_main.run (default_raw_context ()) with | Ok ctxt -> ctxt @@ -246,12 +243,8 @@ module List_key_values_benchmark_intercept = struct Table.list_key_values ~length:0 ctxt |> Lwt_main.run |> ignore in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end -let () = Registration_helpers.register (module List_key_values_benchmark) +let () = Registration.register (module List_key_values_benchmark) -let () = - Registration_helpers.register (module List_key_values_benchmark_intercept) +let () = Registration.register (module List_key_values_benchmark_intercept) diff --git a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml index 7fc129dacae0..188303905393 100644 --- a/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/ticket_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2022 Trili Tech, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -24,9 +25,10 @@ (*****************************************************************************) open Protocol +open Benchmarks_proto open Alpha_context -let ns = Namespace.make Registration_helpers.ns "tickets" +let ns = Namespace.make Registration.ns "tickets" let fv s = Free_variable.of_namespace (ns s) @@ -87,14 +89,14 @@ module Compare_ticket_hash_benchmark : Benchmark.S = struct let generated_code_destination = None - let compare_model = + let group = Benchmark.Group "compare_tickets" + + let model = Model.make ~conv:(fun () -> ()) - ~model:(Model.unknown_const1 ~name ~const:(fv "compare_ticket_hash")) - - let models = [("compare_tickets", compare_model)] + ~model:(Model.unknown_const1 ~const:(fv "compare_ticket_hash")) - let benchmark rng_state _conf () = + let create_benchmark ~rng_state _conf = let bytes = Base_samplers.bytes rng_state ~size:{min = 1; max = 64} in let hash = Ticket_hash.of_script_expr_hash @@ Script_expr_hash.hash_bytes [bytes] @@ -105,12 +107,9 @@ module Compare_ticket_hash_benchmark : Benchmark.S = struct let workload = () in let closure () = ignore (Ticket_hash.compare hash hash2) in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end -let () = Registration_helpers.register (module Compare_ticket_hash_benchmark) +let () = Registration.register (module Compare_ticket_hash_benchmark) (** A benchmark for {!Ticket_costs.Constants.cost_compare_key_contract}. @@ -142,14 +141,14 @@ module Compare_key_contract_benchmark : Benchmark.S = struct let generated_code_destination = None - let compare_model = + let group = Benchmark.Group "compare_tickets" + + let model = Model.make ~conv:(fun () -> ()) - ~model:(Model.unknown_const1 ~name ~const:(fv "compare_contract")) - - let models = [("compare_tickets", compare_model)] + ~model:(Model.unknown_const1 ~const:(fv "compare_contract")) - let benchmark rng_state _conf () = + let create_benchmark ~rng_state _conf = let bytes = Base_samplers.bytes rng_state ~size:{min = 32; max = 64} in let branch = Block_hash.hash_bytes [bytes] in let op_hash = Operation.hash_raw {shell = {branch}; proto = bytes} in @@ -159,12 +158,9 @@ module Compare_key_contract_benchmark : Benchmark.S = struct let workload = () in let closure () = ignore (Contract.compare contract contract2) in Generator.Plain {workload; closure} - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (benchmark rng_state config) end -let () = Registration_helpers.register (module Compare_key_contract_benchmark) +let () = Registration.register (module Compare_key_contract_benchmark) (* A simple ticket type for use in the benchmarks. *) let ticket_ty = @@ -204,6 +200,8 @@ module Has_tickets_type_benchmark : Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + let make_bench_helper rng_state config () = let open Result_syntax in let* ctxt, _ = Lwt_main.run (Execution_context.make ~rng_state) in @@ -218,29 +216,17 @@ module Has_tickets_type_benchmark : Benchmark.S = struct let closure () = ignore (Ticket_scanner.type_has_tickets ctxt ty) in ok (Generator.Plain {workload; closure}) - let make_bench rng_state config () = + let create_benchmark ~rng_state config = match make_bench_helper rng_state config () with | Ok closure -> closure | Error trace -> raise (Ticket_benchmark_error {benchmark_name = name; trace}) - let size_model = - Model.make - ~conv:(function {nodes} -> (nodes, ())) - ~model: - (Model.affine - ~name - ~intercept: - (fv (Format.asprintf "%s_const" (Namespace.basename name))) - ~coeff:(fv (Format.asprintf "%s_coeff" (Namespace.basename name)))) - - let models = [("size_has_tickets_model", size_model)] - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) + let model = + Model.make ~conv:(function {nodes} -> (nodes, ())) ~model:Model.affine end -let () = Registration_helpers.register (module Has_tickets_type_benchmark) +let () = Registration.register (module Has_tickets_type_benchmark) let ticket_sampler rng_state = let seed = Base_samplers.uniform_bytes ~nbytes:32 rng_state in @@ -261,6 +247,8 @@ module Collect_tickets_benchmark : Benchmark.S = struct let generated_code_destination = None + let group = Benchmark.Standalone + let make_bench_helper rng_state config () = let open Script_typed_ir in let open Result_syntax in @@ -290,26 +278,14 @@ module Collect_tickets_benchmark : Benchmark.S = struct in ok (Generator.Plain {workload; closure}) - let make_bench rng_state config () = + let create_benchmark ~rng_state config = match make_bench_helper rng_state config () with | Ok closure -> closure | Error trace -> raise (Ticket_benchmark_error {benchmark_name = name; trace}) - let size_model = - Model.make - ~conv:(function {nodes} -> (nodes, ())) - ~model: - (Model.affine - ~name - ~intercept: - (fv (Format.asprintf "%s_const" (Namespace.basename name))) - ~coeff:(fv (Format.asprintf "%s_coeff" (Namespace.basename name)))) - - let models = [("size_collect_tickets_step_model", size_model)] - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) + let model = + Model.make ~conv:(function {nodes} -> (nodes, ())) ~model:Model.affine end -let () = Registration_helpers.register (module Collect_tickets_benchmark) +let () = Registration.register (module Collect_tickets_benchmark) diff --git a/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml b/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml index a1bd650460b8..353ae6ea1710 100644 --- a/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml +++ b/src/proto_alpha/lib_benchmarks_proto/translator_benchmarks.ml @@ -2,6 +2,7 @@ (* *) (* Open Source License *) (* Copyright (c) 2021-2022 Nomadic Labs, *) +(* Copyright (c) 2023 Marigold *) (* *) (* Permission is hereby granted, free of charge, to any person obtaining a *) (* copy of this software and associated documentation files (the "Software"),*) @@ -545,6 +546,8 @@ let check_printable_benchmark = let () = Registration_helpers.register check_printable_benchmark +open Benchmarks_proto + module Ty_eq : Benchmark.S = struct type config = {max_size : int} @@ -581,16 +584,12 @@ module Ty_eq : Benchmark.S = struct let tags = [Tags.translator] - let intercept_var = fv (Format.asprintf "%s_const" (Namespace.basename name)) - - let coeff_var = fv (Format.asprintf "%s_coeff" (Namespace.basename name)) + let group = Benchmark.Group "size_translator_model" - let size_model = + let model = Model.make ~conv:(function Ty_eq_workload {nodes; _} -> (nodes, ())) - ~model:(Model.affine ~name ~intercept:intercept_var ~coeff:coeff_var) - - let models = [("size_translator_model", size_model)] + ~model:Model.affine let ty_eq_benchmark rng_state nodes (ty : Script_typed_ir.ex_ty) = Lwt_main.run @@ -627,7 +626,7 @@ module Ty_eq : Benchmark.S = struct | Ok closure -> closure | Error errs -> global_error name errs - let make_bench rng_state (cfg : config) () = + let create_benchmark ~rng_state (cfg : config) = let nodes = Base_samplers.( sample_in_interval ~range:{min = 1; max = cfg.max_size} rng_state) @@ -636,12 +635,9 @@ module Ty_eq : Benchmark.S = struct Michelson_generation.Samplers.Random_type.m_type ~size:nodes rng_state in ty_eq_benchmark rng_state nodes ty - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) end -let () = Registration_helpers.register (module Ty_eq) +let () = Registration.register (module Ty_eq) (* A dummy type generator, sampling linear terms of a given size. The generator always returns types of the shape: @@ -728,7 +724,9 @@ module Parse_type_benchmark : Benchmark.S = struct let generated_code_destination = None - let make_bench rng_state config () = + let group = Benchmark.Group "size_translator_model" + + let create_benchmark ~rng_state config = ( Lwt_main.run (Execution_context.make ~rng_state) >>? fun (ctxt, _) -> let ctxt = Gas_helpers.set_limit ctxt in let size = Random.State.int rng_state config.max_size in @@ -755,23 +753,13 @@ module Parse_type_benchmark : Benchmark.S = struct | Ok closure -> closure | Error errs -> global_error name errs - let size_model = + let model = Model.make ~conv:(function Type_workload {nodes; consumed = _} -> (nodes, ())) - ~model: - (Model.affine - ~name - ~intercept: - (fv (Format.asprintf "%s_const" (Namespace.basename name))) - ~coeff:(fv (Format.asprintf "%s_coeff" (Namespace.basename name)))) - - let models = [("size_translator_model", size_model)] - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) + ~model:Model.affine end -let () = Registration_helpers.register (module Parse_type_benchmark) +let () = Registration.register (module Parse_type_benchmark) module Unparse_type_benchmark : Benchmark.S = struct include Parse_type_shared @@ -784,7 +772,9 @@ module Unparse_type_benchmark : Benchmark.S = struct let generated_code_destination = None - let make_bench rng_state config () = + let group = Benchmark.Group "size_translator_model" + + let create_benchmark ~rng_state config = ( Lwt_main.run (Execution_context.make ~rng_state) >>? fun (ctxt, _) -> let ctxt = Gas_helpers.set_limit ctxt in let size = Random.State.int rng_state config.max_size in @@ -808,20 +798,10 @@ module Unparse_type_benchmark : Benchmark.S = struct | Ok closure -> closure | Error errs -> global_error name errs - let size_model = + let model = Model.make ~conv:(function Type_workload {nodes; consumed = _} -> (nodes, ())) - ~model: - (Model.affine - ~name - ~intercept: - (fv (Format.asprintf "%s_const" (Namespace.basename name))) - ~coeff:(fv (Format.asprintf "%s_coeff" (Namespace.basename name)))) - - let models = [("size_translator_model", size_model)] - - let create_benchmarks ~rng_state ~bench_num config = - List.repeat bench_num (make_bench rng_state config) + ~model:Model.affine end -let () = Registration_helpers.register (module Unparse_type_benchmark) +let () = Registration.register (module Unparse_type_benchmark) diff --git a/tezt/snoop/perform_inference.ml b/tezt/snoop/perform_inference.ml index b1fe281811e5..289e6e1f8432 100644 --- a/tezt/snoop/perform_inference.ml +++ b/tezt/snoop/perform_inference.ml @@ -41,8 +41,8 @@ let models = "cache/CACHE_UPDATE/model"; "ir_size_model"; "carbonated_map"; - "size_collect_tickets_step_model"; - "size_has_tickets_model"; + "tickets/COLLECT_TICKETS_STEP/model"; + "tickets/TYPE_HAS_TICKETS/model"; "compare_tickets"; "list_key_values"; "skip_list/next/model"; -- GitLab