bb/data_smart: fix override syntax warning
A message that is not in the archive (sent off-list or not yet received): [email protected]
PATCH 2/3 bb/data_smart: fix override syntax warning
when defining a function do_removesomething,
the parser warned about
Variable do_removesomething contains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbake
correct it would be to search for a override operator at the end of the string or for the next operator
--- lib/bb/data_smart.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-)
lib/bb/data_smart.py +1 -2
@@ -539,8 +539,7 @@ class DataSmart(MutableMapping): return var in self.overridedata def setVar(self, var, value, **loginfo): - - if not var.startswith("__anon_") and ("_append" in var or "_prepend" in var or "_remove" in var): + if not var.startswith("__anon_") and re.search(r"(_append|_prepend|_remove)(_|$)", var): info = "%s" % var if "file" in loginfo: info += " file: %s" % loginfo["file"]
Signature · 1 line
2.34.1
Quoted 21 lines · Konrad Weihmann via lists.openembedded.org
when defining a function
do_removesomething,
the parser warned aboutVariable
do_removesomethingcontains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbakecorrect it would be to search for a override operator at the end of the string or for the next operator
Signed-off-by Konrad Weihmann <[email protected]>---
lib/bb/data_smart.py | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)lib/bb/data_smart.py +0
-0@@ -539,8 +539,7 @@ class DataSmart(MutableMapping):return var in self.overridedata
Quoted 9 lines
defsetVar(self, var, value, **loginfo):
-
- if notvar.startswith("__anon_")and ("_append" in var or "_prepend" in var or "_remove" in var):
+ if notvar.startswith("__anon_")andre.search(r"(_append|_prepend|_remove)(_|$)", var):
info = "%s" % var
if "file" in loginfo:
info += " file: %s" % loginfo["file"]
We can't add a non pre-compiled regex into a code hot path. Even a precompiled regex is going to be relatively slow at that code point. That is why it is using "in" and it was a relatively loose test.
Cheers,
Richard
Richard, this is in my opinion wrong.It's preventing, for no reason, valid tasks.I agree that it's an expensive operation (potentially requiring to making it precompiled), but I honestly don't follow your take that this will be of any significance when taking a full (ordinary) build into account - the penalty of the operation is in a millisecond range while a typical task/image build is more considered within a minute range.If that "penalty" is unacceptable I at least would expect the documentation to explicitly name this limitation (currently I don't see that anywhere). So either way we would require a change, it's just unclear to me what's the consensus in the community.My take would be to prefer precision over performance - not sure how others think about it.
Side note: the original patch never got any selftests, which just kept hiding the problem IMO
Quoted 21 lines · Konrad Weihmann via lists.openembedded.org
when defining a function
do_removesomething,
the parser warned aboutVariable
do_removesomethingcontains an operation using the old override syntax. Please convert this layer/metadata before attempting to use with a newer bitbakecorrect it would be to search for a override operator at the end of the string or for the next operator
Signed-off-by Konrad Weihmann <[email protected]>---
lib/bb/data_smart.py | 3 +--1 file changed, 1 insertion(+), 2 deletions(-)lib/bb/data_smart.py +0
-0@@ -539,8 +539,7 @@ class DataSmart(MutableMapping):return var in self.overridedata
Quoted 9 lines
defsetVar(self, var, value, **loginfo):
-
- if notvar.startswith("__anon_")and ("_append" in var or "_prepend" in var or "_remove" in var):
+ if notvar.startswith("__anon_")andre.search(r"(_append|_prepend|_remove)(_|$)", var):
info = "%s" % var
if "file" in loginfo:
info += " file: %s" % loginfo["file"]
We can't add a non pre-compiled regex into a code hot path. Even a precompiled regex is going to be relatively slow at that code point. That is why it is using "in" and it was a relatively loose test.
Cheers,
Richard
Quoted 1 line · Konrad Weihmann
Richard, this is in my opinion wrong.
Noted.
Quoted 10 lines
It's preventing, for no reason, valid tasks.
I agree that it's an expensive operation (potentially requiring to making it precompiled), but I honestly don't follow your take that this will be of any significance when taking a full (ordinary) build into account - the penalty of the operation is in a millisecond range while a typical task/image build is more considered within a minute range.
If that "penalty" is unacceptable I at least would expect the documentation to explicitly name this limitation (currently I don't see that anywhere).
The penalty I worry about is against parse time. That *is* a serious concern for usability. Lots of small changes like this mount up. I happen to know (as someone who as done a lot of performance and profiling work against bitbake) that setVar is on the hot path.
Quoted 2 lines
So either way we would require a change, it's just unclear to me what's the consensus in the community.
No, we don't *require* a change. You're asking for a change, I'm saying I don't think it is good for the performance penalty vs the gain.
Quoted 5 lines
My take would be to prefer precision over performance - not sure how others think about it.
Side note: the original patch never got any selftests, which just kept hiding the problem IMO
FWIW nothing is requiring you to have tasks named like that.
Cheers,
Richard
Quoted 27 lines · Richard Purdie
Quoted 1 line · Konrad Weihmann
Richard, this is in my opinion wrong.
Noted.
Quoted 10 lines
It's preventing, for no reason, valid tasks.
I agree that it's an expensive operation (potentially requiring to making it precompiled), but I honestly don't follow your take that this will be of any significance when taking a full (ordinary) build into account - the penalty of the operation is in a millisecond range while a typical task/image build is more considered within a minute range.
If that "penalty" is unacceptable I at least would expect the documentation to explicitly name this limitation (currently I don't see that anywhere).The penalty I worry about is against parse time. That *is* a serious concern for usability. Lots of small changes like this mount up. I happen to know (as someone who as done a lot of performance and profiling work against bitbake) that setVar is on the hot path.
Quoted 2 lines
So either way we would require a change, it's just unclear to me what's the consensus in the community.
No, we don't *require* a change. You're asking for a change, I'm saying I don't think it is good for the performance penalty vs the gain.
Quoted 7 lines
Quoted 5 lines
My take would be to prefer precision over performance - not sure how others think about it.
Side note: the original patch never got any selftests, which just kept hiding the problem IMO
FWIW nothing is requiring you to have tasks named like that.
I find it troublesome that a generic build system doesn't mention that as reserved keyword/pattern - esp as the printed hint isn't exactly helpful (tbh I was scratching my head for a minute to see the "old" override syntax in the example)
I agree (also as I believe setVar is fired million of times throughout an ordinary build) about the performance penalty.
But what about removing this code path entirely and letting those vars to be set in the data smart?
And then probe for variables having one of those pattern for instance close to the finalization (which I believe should give a overall performance gain) (line info can still be gathered from varhistory if needed). Would that be a way forward?
Or one can even think about moving that stuff into a sanity check, instead of erroring out that early here (and potentially often).
Quoted 4 lines
Cheers,
Richard
What about using precompiled re only in cases where the old "in" is triggered already?
Quoted 69 lines · Konrad Weihmann via lists.openembedded.org
Quoted 27 lines · Richard Purdie
Quoted 1 line · Konrad Weihmann
Richard, this is in my opinion wrong.
Noted.
Quoted 10 lines
It's preventing, for no reason, valid tasks.
I agree that it's an expensive operation (potentially requiring to making it precompiled), but I honestly don't follow your take that this will be of any significance when taking a full (ordinary) build into account - the penalty of the operation is in a millisecond range while a typical task/image build is more considered within a minute range.
If that "penalty" is unacceptable I at least would expect the documentation to explicitly name this limitation (currently I don't see that anywhere).The penalty I worry about is against parse time. That *is* a serious concern for usability. Lots of small changes like this mount up. I happen to know (as someone who as done a lot of performance and profiling work against bitbake) that setVar is on the hot path.
Quoted 2 lines
So either way we would require a change, it's just unclear to me what's the consensus in the community.
No, we don't *require* a change. You're asking for a change, I'm saying I don't think it is good for the performance penalty vs the gain.
Quoted 7 lines
Quoted 5 lines
My take would be to prefer precision over performance - not sure how others think about it.
Side note: the original patch never got any selftests, which just kept hiding the problem IMO
FWIW nothing is requiring you to have tasks named like that.
I find it troublesome that a generic build system doesn't mention that as reserved keyword/pattern - esp as the printed hint isn't exactly helpful (tbh I was scratching my head for a minute to see the "old" override syntax in the example)
I agree (also as I believe setVar is fired million of times throughout an ordinary build) about the performance penalty.
But what about removing this code path entirely and letting those vars to be set in the data smart?
And then probe for variables having one of those pattern for instance close to the finalization (which I believe should give a overall performance gain) (line info can still be gathered from varhistory if needed).
Would that be a way forward?Or one can even think about moving that stuff into a sanity check, instead of erroring out that early here (and potentially often).
Quoted 4 lines
Cheers,
Richard
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16584): https://lists.openembedded.org/g/bitbake-devel/message/16584
Mute This Topic: https://lists.openembedded.org/mt/108574686/3617156
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 2 lines · Martin Jansa
What about using precompiled re only in cases where the old "in" is triggered already?
Also acceptable for me - anything that makes the check less opaque.
@Richard please let me know how we could proceed from here.
My personal take, after digging into all the side effects, would be to remove the check and treat all "old syntax" overrides as merely "typos", hence letting them slip into the datasmart store, but adding a (potentially warning level) note that a certain operation is using the old syntax and therefore not being applicable in the current context. (unless ofc there is some code path that does some bad things to the store when using the old syntax, which haven't come across after looking at the code)
Quoted 73 lines
Quoted 69 lines · Konrad Weihmann via lists.openembedded.org
Quoted 27 lines · Richard Purdie
Quoted 1 line · Konrad Weihmann
Richard, this is in my opinion wrong.
Noted.
Quoted 10 lines
It's preventing, for no reason, valid tasks.
I agree that it's an expensive operation (potentially requiring to making it precompiled), but I honestly don't follow your take that this will be of any significance when taking a full (ordinary) build into account - the penalty of the operation is in a millisecond range while a typical task/image build is more considered within a minute range.
If that "penalty" is unacceptable I at least would expect the documentation to explicitly name this limitation (currently I don't see that anywhere).The penalty I worry about is against parse time. That *is* a serious concern for usability. Lots of small changes like this mount up. I happen to know (as someone who as done a lot of performance and profiling work against bitbake) that setVar is on the hot path.
Quoted 2 lines
So either way we would require a change, it's just unclear to me what's the consensus in the community.
No, we don't *require* a change. You're asking for a change, I'm saying I don't think it is good for the performance penalty vs the gain.
Quoted 7 lines
Quoted 5 lines
My take would be to prefer precision over performance - not sure how others think about it.
Side note: the original patch never got any selftests, which just kept hiding the problem IMO
FWIW nothing is requiring you to have tasks named like that.
I find it troublesome that a generic build system doesn't mention that as reserved keyword/pattern - esp as the printed hint isn't exactly helpful (tbh I was scratching my head for a minute to see the "old" override syntax in the example)
I agree (also as I believe setVar is fired million of times throughout an ordinary build) about the performance penalty.
But what about removing this code path entirely and letting those vars to be set in the data smart?
And then probe for variables having one of those pattern for instance close to the finalization (which I believe should give a overall performance gain) (line info can still be gathered from varhistory if needed).
Would that be a way forward?Or one can even think about moving that stuff into a sanity check, instead of erroring out that early here (and potentially often).
Quoted 4 lines
Cheers,
Richard
-=-=-=-=-=-=-=-=-=-=-=-
Links: You receive all messages sent to this group.
View/Reply Online (#16584): https://lists.openembedded.org/g/bitbake-devel/message/16584
Mute This Topic: https://lists.openembedded.org/mt/108574686/3617156
Group Owner: [email protected]
Unsubscribe: https://lists.openembedded.org/g/bitbake-devel/unsub [[email protected]]
-=-=-=-=-=-=-=-=-=-=-=-
Quoted 10 lines · Konrad Weihmann
Quoted 2 lines · Martin Jansa
What about using precompiled re only in cases where the old "in" is triggered already?
Also acceptable for me - anything that makes the check less opaque.
@Richard please let me know how we could proceed from here.
Quoted 8 lines
My personal take, after digging into all the side effects, would be to remove the check and treat all "old syntax" overrides as merely "typos", hence letting them slip into the datasmart store, but adding a (potentially warning level) note that a certain operation is using the old syntax and therefore not being applicable in the current context. (unless ofc there is some code path that does some bad things to the store when using the old syntax, which haven't come across after looking at the code)
Old syntax won't hurt the store, the challenge is again performance. Iterating the datastore for a search is one of the slowest things we can do. That was why the check was put on entry rather than exit.
My original reply was intending to suggest the patch be tweaked to improve performance along the lines Martin suggested (or otherwise).
In python if you have:
"if A and B and C:"
C isn't evaluated unless A and B are true so there should be some way to keep performance and improve the tests.
I did even wonder about dropping those tests at this point, not sure if we're ready to do that or not yet...
Cheers,
Richard
Hi all,
Quoted 29 lines · Richard Purdie via lists.openembedded.org
Quoted 10 lines · Konrad Weihmann
Quoted 2 lines · Martin Jansa
What about using precompiled re only in cases where the old "in" is triggered already?
Also acceptable for me - anything that makes the check less opaque.
@Richard please let me know how we could proceed from here.
Quoted 8 lines
My personal take, after digging into all the side effects, would be to remove the check and treat all "old syntax" overrides as merely "typos", hence letting them slip into the datasmart store, but adding a (potentially warning level) note that a certain operation is using the old syntax and therefore not being applicable in the current context. (unless ofc there is some code path that does some bad things to the store when using the old syntax, which haven't come across after looking at the code)
Old syntax won't hurt the store, the challenge is again performance. Iterating the datastore for a search is one of the slowest things we can do. That was why the check was put on entry rather than exit.
My original reply was intending to suggest the patch be tweaked to improve performance along the lines Martin suggested (or otherwise).
In python if you have:
Quoted 8 lines
"if A and B and C:"
C isn't evaluated unless A and B are true so there should be some way to keep performance and improve the tests.
I did even wonder about dropping those tests at this point, not sure if we're ready to do that or not yet...
May I suggest doing a split on _ and then check if one of the reserved keywords make it there?
e.g.
any(x in ("append", "prepend", "remove") for x in var.split("_"))
instead of using a re string for that?
I tested with:
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
s = [1, 2, 3, 4]
def test(x):
... print(f"{x}")
...
Quoted 1 line
Quoted 1 line
Quoted 1 line
any(test(x) or x % 2 for x in s)
1
True
Quoted 1 line
Quoted 1 line
Quoted 1 line
any(test(x) or x // 2 for x in s)
1
2
True
in what I assume is CPython (python3 in fedora40), 3.12.6. It seems it stops at the first found True so we save a few checks.
Now I'm wondering if var.split("_") creates the whole list at call time or if it's a lazy iterator, e.g. using yield internally so that it's actually doing what it needs for each iteration of the loop and not more.
No clue if this is consistent for other implementations of the python interpreter such as Jython.
Additionally, this still wouldn't fix the presence of _remove_ in the task name triggering the check. I could e.g. see a do_remove_unused_files() in an image recipe for example. So I would agree that adding some info in the documentation would make sense to discourage people to name their function this way.
Cheers,
Quentin
Quoted 2 lines · Quentin Schulz
any(x in ("append", "prepend", "remove") for x in var.split("_"))
I ran a test with timeit (5 repetitions, 100000 runs). with various ways to implement that check (not all of them perfect)
here's the code
----
import timeit
pattern = [
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and re.search(r"(_append|_prepend|_remove)(_|$)", var):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and re.search(pattern, var):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and (var.endswith("_append") or var.endswith("_prepend") or var.endswith("_remove")):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and (var.rfind("_append") != -1 or var.rfind("_prepend") != -1 or var.rfind("_remove") != -1):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and any(x in var for x in ["_append", "_prepend", "_remove"]):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and ("_append" in var or "_prepend" in var or "_remove" in var):
pass
''',
'''
var = 'do_removesomething'
if not var.startswith("__anon_") and any(x in ("append", "prepend", "remove") for x in var.split("_")) :
pass
''',
]
setup = '''
import re
pattern = re.compile(r"(_append|_prepend|_remove)(_|$)")
'''
res = []
import statistics
for index, pat in enumerate(pattern):
print(f'Pattern {index} = {statistics.mean(timeit.repeat(pat,
setup=setup, number=1000000))}')
---
and here are the results
Pattern 0 = 0.6844888394000008
Pattern 1 = 0.9764905843883753
Pattern 2 = 0.32475767740397715
Pattern 3 = 0.3955688206013292
Pattern 4 = 0.5456381111929659
Pattern 5 = 0.17395127240451985
Pattern 6 = 0.5362491855979897
"Pattern 5" being the current implementation.
"Pattern 6" your suggestion.
So I think the penalty of the split will be way too high
Hi Konrad,
Quoted 47 lines · Konrad Weihmann
Quoted 2 lines · Quentin Schulz
any(x in ("append", "prepend", "remove") for x in var.split("_"))I ran a test with timeit (5 repetitions, 100000 runs). with various ways to implement that check (not all of them perfect)
here's the code
----import timeit
pattern = [
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")andre.search(r"(_append|_prepend| _remove)(_|$)", var):
pass
''',
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")andre.search(pattern, var):
pass
''',
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")and (var.endswith("_append")orvar.endswith("_prepend")orvar.endswith("_remove")):
pass
''',
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")and (var.rfind("_append")!= -1 orvar.rfind("_prepend")!= -1 orvar.rfind("_remove")!= -1):
pass
''',
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")andany(x in var for x in ["_append", "_prepend", "_remove"]):
pass
''',
'''
var = 'do_removesomething'
if notvar.startswith("__anon_")and ("_append" in var or "_prepend" in var or "_remove" in var):
pass
''',
'''
Quoted 8 lines
var = '
do_removesomething'
if notvar.startswith("__anon_")andany(x in ("append", "prepend", "remove") for x in var.split("_")):
pass
''',
]
setup = '''
import re
pattern = re.compile(r"(_append|_prepend|_remove)(_|$)")
By having two variables named pattern, this was a bit confusing to read.
So, the thing is... those aren't actually testing the same things.
pattern2 only checks if the function ends with _append/_remove/_prepend instead of checking if it also appears somewhere in the string (which is what we do today). Additionally, we could merge all those into one function with var.endswith(('_append', '_prepend', '_remove')).
Not sure why we would use rfind instead of find in pattern3?
For pattern4, I think you may want to use a tuple instead of an array, it's usually better optimized as tuples are immutable in Python.
What about pattern6:
if not var.startswith("__anon_") and (("_append" in var and (var.endswith("_append") or "_append_" in var)) or ("_prepend" in var and (var.endswith("_prepend") or "_prepend_" in var)) or ("_remove" in var and (var.endswith("_remove") or "_remove_" in var))):
and pattern7:
if not var.startswith("__anon_") and ((var.endswith("_append") or "_append_" in var) or (var.endswith("_prepend") or "_prepend_" in var) or (var.endswith("_remove") or "_remove_" in var)):
Quoted 9 lines
'''
res = []import statistics
for index, pat in enumerate(pattern):
print(f'Pattern {index} = {statistics.mean(timeit.repeat(pat,
setup=setup, number=1000000))}')
Why are we compiling the re for cases where we don't need it? I'm also not entirely sure how much is kept in cache here? Should we spawn a new interpreter and clear caches before each iteration of the pattern (the same interpreter for the 1000000 instances of that one pattern).
Cheers,
Quentin
Quoted 29 lines · Richard Purdie
Quoted 10 lines · Konrad Weihmann
Quoted 2 lines · Martin Jansa
What about using precompiled re only in cases where the old "in" is triggered already?
Also acceptable for me - anything that makes the check less opaque.
@Richard please let me know how we could proceed from here.
Quoted 8 lines
My personal take, after digging into all the side effects, would be to remove the check and treat all "old syntax" overrides as merely "typos", hence letting them slip into the datasmart store, but adding a (potentially warning level) note that a certain operation is using the old syntax and therefore not being applicable in the current context. (unless ofc there is some code path that does some bad things to the store when using the old syntax, which haven't come across after looking at the code)
Old syntax won't hurt the store, the challenge is again performance. Iterating the datastore for a search is one of the slowest things we can do. That was why the check was put on entry rather than exit.
My original reply was intending to suggest the patch be tweaked to improve performance along the lines Martin suggested (or otherwise).
In python if you have:
Quoted 7 lines
"if A and B and C:"
C isn't evaluated unless A and B are true so there should be some way to keep performance and improve the tests.
I did even wonder about dropping those tests at this point, not sure if we're ready to do that or not yet...
Send out a v2 of the patch, taking Martin's suggestion into account.
Also a patch is out that removes the functionality.
For latter one a consensus in the a wider community is required, so I put it up as a RFC.
Quoted 4 lines
Cheers,
Richard
PATCH 3/3 tests/parse: add coverage for old override syntax
In reply to a message not in the archiveincluding previously unconvered tests for true failure cases of _prepend/_append/_remove.
In addition add tests for not valid cases
--- lib/bb/tests/parse.py | 69 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+)
lib/bb/tests/parse.py +69 -0
@@ -132,6 +132,75 @@ DESCRIPTION:${PN}-dev = "${DESCRIPTION} B" PN = "bc" """ + override_old_append = """ +EXTRA_OECONF_append = " c" +""" + + def test_parse_old_override_syntax_append(self): + f = self.parsehelper(self.override_old_append) + try: + bb.parse.handle(f.name, self.d)[''] + self.fail('Pattern should have raised bb.BBHandledException') + except bb.BBHandledException: + pass + + override_old_prepend = """ +EXTRA_OECONF_prepend = " c" +""" + + def test_parse_old_override_syntax_prepend(self): + f = self.parsehelper(self.override_old_prepend) + try: + bb.parse.handle(f.name, self.d)[''] + self.fail('Pattern should have raised bb.BBHandledException') + except bb.BBHandledException: + pass + + override_old_remove = """ +EXTRA_OECONF_remove = " c" +""" + + def test_parse_old_override_syntax_remove(self): + f = self.parsehelper(self.override_old_remove) + try: + bb.parse.handle(f.name, self.d)[''] + self.fail('Pattern should have raised bb.BBHandledException') + except bb.BBHandledException: + pass + + override_old_valid_append = """ +do_appendsomething () { + : +} +addtask do_appendsomething +""" + + def test_parse_old_override_syntax_no_warning_append(self): + f = self.parsehelper(self.override_old_valid_append) + bb.parse.handle(f.name, self.d)[''] + + override_old_valid_prepend = """ +do_prependsomething () { + : +} +addtask do_prependsomething +""" + + def test_parse_old_override_syntax_no_warning_prepend(self): + f = self.parsehelper(self.override_old_valid_prepend) + bb.parse.handle(f.name, self.d)[''] + + override_old_valid_remove = """ +do_removesomething () { + : +} +addtask do_removesomething +""" + + def test_parse_old_override_syntax_no_warning_remove(self): + f = self.parsehelper(self.override_old_valid_remove) + bb.parse.handle(f.name, self.d)[''] + def test_parse_combinations(self): f = self.parsehelper(self.overridetest3) d = bb.parse.handle(f.name, self.d)['']
Signature · 1 line
2.34.1