bitbake: event: Fix multiconfig event handler change performance regressions

There were two issues in this code, firstly the code could stack duplicates
in the variable, secondly, calling "if data" caused the datastore to compute
len(data) which is comparitively expensive. Checking "if data is not None"
is much much faster/cheaper.

The issue was clear from "bitbake -p -P" output where the time in register()
showed large amounts of time in the __len__ function of the datastore.

(Bitbake rev: 9298d08b7dcf9d79f54536f87686d65c4ad7deb9)

Signed-off-by: Richard Purdie <richard.purdie@linuxfoundation.org>
This commit is contained in:
Richard Purdie
2021-03-11 13:43:12 +00:00
parent e6ec2b4dcc
commit b1a5b43735

View File

@@ -118,7 +118,7 @@ def fire_class_handlers(event, d):
if _eventfilter:
if not _eventfilter(name, handler, event, d):
continue
if d and not name in (d.getVar("__BBHANDLERS_MC") or []):
if d and not name in (d.getVar("__BBHANDLERS_MC") or set()):
continue
execute_handler(name, handler, event, d)
@@ -232,15 +232,15 @@ noop = lambda _: None
def register(name, handler, mask=None, filename=None, lineno=None, data=None):
"""Register an Event handler"""
if data and data.getVar("BB_CURRENT_MC"):
if data is not None and data.getVar("BB_CURRENT_MC"):
mc = data.getVar("BB_CURRENT_MC")
name = '%s%s' % (mc.replace('-', '_'), name)
# already registered
if name in _handlers:
if data:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or [])
bbhands_mc.append(name)
if data is not None:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or set())
bbhands_mc.add(name)
data.setVar("__BBHANDLERS_MC", bbhands_mc)
return AlreadyRegistered
@@ -278,16 +278,16 @@ def register(name, handler, mask=None, filename=None, lineno=None, data=None):
_event_handler_map[m] = {}
_event_handler_map[m][name] = True
if data:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or [])
bbhands_mc.append(name)
if data is not None:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or set())
bbhands_mc.add(name)
data.setVar("__BBHANDLERS_MC", bbhands_mc)
return Registered
def remove(name, handler, data=None):
"""Remove an Event handler"""
if data:
if data is not None:
if data.getVar("BB_CURRENT_MC"):
mc = data.getVar("BB_CURRENT_MC")
name = '%s%s' % (mc.replace('-', '_'), name)
@@ -299,8 +299,8 @@ def remove(name, handler, data=None):
if name in _event_handler_map[event]:
_event_handler_map[event].pop(name)
if data:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or [])
if data is not None:
bbhands_mc = (data.getVar("__BBHANDLERS_MC") or set())
if name in bbhands_mc:
bbhands_mc.remove(name)
data.setVar("__BBHANDLERS_MC", bbhands_mc)