From 3225978008f481987163ac9918a0bde41788306c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 21 Apr 2024 21:02:32 +0100 Subject: [PATCH 1/3] CP-51701: [perf] Xapi_event: do not convert to lowercase if already lowercase MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Tasks are lowercase Signed-off-by: Edwin Török --- ocaml/xapi/xapi_event.ml | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ocaml/xapi/xapi_event.ml b/ocaml/xapi/xapi_event.ml index 8c7432106ab..9a04233abdd 100644 --- a/ocaml/xapi/xapi_event.ml +++ b/ocaml/xapi/xapi_event.ml @@ -49,6 +49,10 @@ module Token = struct Printf.sprintf "%020Ld,%020Ld" last last_t end +let is_lowercase_char c = Char.equal (Char.lowercase_ascii c) c + +let is_lowercase str = String.for_all is_lowercase_char str + module Subscription = struct type t = Class of string | Object of string * string | All @@ -71,7 +75,7 @@ module Subscription = struct (** [table_matches subs tbl]: true if at least one subscription from [subs] would select some events from [tbl] *) let table_matches subs tbl = - let tbl = String.lowercase_ascii tbl in + let tbl = if is_lowercase tbl then tbl else String.lowercase_ascii tbl in let matches = function | All -> true @@ -84,7 +88,7 @@ module Subscription = struct (** [event_matches subs ev]: true if at least one subscription from [subs] selects for specified class and object *) let object_matches subs ty _ref = - let tbl = String.lowercase_ascii ty in + let tbl = if is_lowercase ty then ty else String.lowercase_ascii ty in let matches = function | All -> true From e35d3633819bd6aa94c883e9f7f2e651000ed53b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 21 Apr 2024 20:56:57 +0100 Subject: [PATCH 2/3] CP-51701: [perf] Xapi_event: drop duplicate lowercase_ascii MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Subscription.object_matches already does it Signed-off-by: Edwin Török --- ocaml/xapi/xapi_event.ml | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/ocaml/xapi/xapi_event.ml b/ocaml/xapi/xapi_event.ml index 8c7432106ab..edb0caf9358 100644 --- a/ocaml/xapi/xapi_event.ml +++ b/ocaml/xapi/xapi_event.ml @@ -540,11 +540,7 @@ let from_inner __context session subs from from_t deadline = Db_cache_types.Table.fold_over_recent !last_generation (fun objref {Db_cache_types.Stat.created; modified; deleted} _ (creates, mods, deletes, last) -> - if - Subscription.object_matches subs - (String.lowercase_ascii table) - objref - then + if Subscription.object_matches subs table objref then let last = max last (max modified deleted) in (* mtime guaranteed to always be larger than ctime *) ( ( if created > !last_generation then @@ -574,11 +570,7 @@ let from_inner __context session subs from from_t deadline = Db_cache_types.Table.fold_over_deleted !last_generation (fun objref {Db_cache_types.Stat.created; modified; deleted} (creates, mods, deletes, last) -> - if - Subscription.object_matches subs - (String.lowercase_ascii table) - objref - then + if Subscription.object_matches subs table objref then let last = max last (max modified deleted) in (* mtime guaranteed to always be larger than ctime *) if created > !last_generation then From 9c1fc6ee85d1647fa5bb271943ced1b2a5705f10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Edwin=20T=C3=B6r=C3=B6k?= Date: Sun, 21 Apr 2024 20:58:18 +0100 Subject: [PATCH 3/3] CP-51701: [perf] Xapi_events: replace List.any+map with List.exists MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Edwin Török --- ocaml/xapi/xapi_event.ml | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/ocaml/xapi/xapi_event.ml b/ocaml/xapi/xapi_event.ml index 8c7432106ab..986c200b86d 100644 --- a/ocaml/xapi/xapi_event.ml +++ b/ocaml/xapi/xapi_event.ml @@ -67,8 +67,6 @@ module Subscription = struct (Api_errors.event_subscription_parse_failure, [x]) ) - let any = List.fold_left (fun acc x -> acc || x) false - (** [table_matches subs tbl]: true if at least one subscription from [subs] would select some events from [tbl] *) let table_matches subs tbl = let tbl = String.lowercase_ascii tbl in @@ -80,7 +78,7 @@ module Subscription = struct | Object (x, _) -> x = tbl in - any (List.map matches subs) + List.exists matches subs (** [event_matches subs ev]: true if at least one subscription from [subs] selects for specified class and object *) let object_matches subs ty _ref = @@ -93,7 +91,7 @@ module Subscription = struct | Object (x, y) -> x = tbl && y = _ref in - any (List.map matches subs) + List.exists matches subs (** [event_matches subs ev]: true if at least one subscription from [subs] selects for event [ev] *) let event_matches subs ev = object_matches subs ev.ty ev.reference