diff mbox series

data: Optimise renameVar when a variable doesn't exist

Message ID 20260701135557.3607851-1-richard.purdie@linuxfoundation.org
State Accepted, archived
Commit 660965735c7f16a9e864d8d3cb91298db8c39b81
Headers show
Series data: Optimise renameVar when a variable doesn't exist | expand

Commit Message

Richard Purdie July 1, 2026, 1:55 p.m. UTC
Currently, if a variable doesn't exist, a history entry for the rename is
still created, even if you're renaming nothing to nothing.

That extra data is pretty pointless and we can improve renameVar speed
around 20% in normal parsing operations if we skip it. It will also lower
memory consuption and data store size which will help too.

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
---
 lib/bb/data_smart.py | 10 ++++++++++
 1 file changed, 10 insertions(+)
diff mbox series

Patch

diff --git a/lib/bb/data_smart.py b/lib/bb/data_smart.py
index 110dfa11162..9961269a3f8 100644
--- a/lib/bb/data_smart.py
+++ b/lib/bb/data_smart.py
@@ -669,6 +669,8 @@  class DataSmart(MutableMapping):
             bb.warn("Calling renameVar with equivalent keys (%s) is invalid" % key)
             return
 
+        found = False
+
         val = self.getVar(key, 0, parsing=True)
         if val is not None:
             self.varhistory.rename_variable_hist(key, newkey)
@@ -677,6 +679,7 @@  class DataSmart(MutableMapping):
             loginfo['detail'] = val
             self.varhistory.record(**loginfo)
             self.setVar(newkey, val, ignore=True, parsing=True)
+            found = True
 
         srcflags = self.getVarFlags(key, False, True) or {}
         for i in srcflags:
@@ -688,13 +691,20 @@  class DataSmart(MutableMapping):
             dest = self.getVarFlag(newkey, i, False) or []
             dest.extend(src)
             self.setVarFlag(newkey, i, dest, ignore=True)
+            found = True
 
         if key in self.overridedata:
+            found = True
             self.overridedata[newkey] = []
             for (v, o) in self.overridedata[key]:
                 self.overridedata[newkey].append([v.replace(key, newkey), o])
                 self.renameVar(v, v.replace(key, newkey))
 
+        if not found:
+            # No variable to rename so not worth the work in writing extra
+            # history data for performance
+            return
+
         if ':' in newkey and val is None:
             self._setvar_update_overrides(newkey, **loginfo)