From 92514db7166e5ba6fc2351b0dc45e9e1d90a071f Mon Sep 17 00:00:00 2001 From: Alina Lenk Date: Fri, 19 Apr 2024 22:37:42 +0200 Subject: [PATCH 2/2] generate_packets.py: always transmit new elements in array-diff with variable length See RM #483 Signed-off-by: Alina Lenk --- common/generate_packets.py | 15 ++++++++++++++- common/networking/packets.def | 2 ++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/common/generate_packets.py b/common/generate_packets.py index e4582d8575..4989124e9f 100755 --- a/common/generate_packets.py +++ b/common/generate_packets.py @@ -1435,10 +1435,23 @@ differ = FALSE; """Helper method. Generate array-diff put code.""" # we're nesting two levels deep in the JSON structure sub = location.sub_full(2) - inner_put = prefix(" ", self.elem.get_code_put(sub, True)) + # Note: At the moment, we're only deep-diffing our elements + # if our array size is constant + inner_put = prefix(" ", self.elem.get_code_put(sub, self.size.constant)) inner_cmp = prefix(" ", self.elem.get_code_cmp(sub)) index_put = prefix(" ", self.size.index_put(location.index)) index_put_sentinel = prefix(" ", self.size.index_put(self.size.real)) + + if not self.size.constant: + inner_cmp = f"""\ + if ({location.index} < {self.size.old}) {{ +{prefix(" ", inner_cmp)}\ + }} else {{ + /* Always transmit new elements */ + differ = TRUE; + }} +""" + return f"""\ {self.size.size_check_index(location.name)}\ {{ diff --git a/common/networking/packets.def b/common/networking/packets.def index 7988b7b433..686343fbc5 100644 --- a/common/networking/packets.def +++ b/common/networking/packets.def @@ -165,6 +165,8 @@ Syntax: diff: use the array-diff feature. This will reduce the amount of traffic for large arrays in which only a few elements change. + Note that in multidemensional arrays, the individual sub-arrays + only get diff'd if the higher levels have constant length. add-cap: only transfer this field if the given capability is available at runtime. If you have a capability named -- 2.34.1