gh-145228: Increase performance of _config_dict_get_bool(PyObject *dict, const char *name, int *p_flag) by removing unused PY_DECREF(item)#145229
Conversation
…har *name, int *p_flag) by removing unused PY_DECREF(item)
|
I don't think we need a NEWS entry here. Also, this code is not a hot path, and perf changes will be negligible. On the other hand, if this change will be accepted, I propose to rewrite whole condition in more readable version like: |
|
cc @picnixz |
|
Hi! Thanks for the review! I'm not deep into this, so I'm not 100% sure whether the suggestion is correct (so I think that this is probably correct, but maybe there are some edge cases why this was done this way? but probably you're right), so if it's the same, I'll add the suggestion. And I think that (although this might not be a hot path) the change makes sense because why should we leave unnecessary statements in the code (if we did this forever and we never removed "old" things, then the code will start to grow and grow without any end, so I don't really see a reson not to do this). |
Thinking of something like item == null or any other thing (I didn't check this for this case, but just an example for those potential edge cases) |
|
It is not a hot path and I don't think it will really help. So I prefer leaving things as is. Note that we sometimes prefer slightly slower code for the sake of maintenance. |
Because we do not want to add code churn. This is explained in the devguide as well. |
Fixes #145228
In
Python/interpconfig.cwe usePy_DECREF(item);in line 118 herewhile it's not necessary here
because we use
if (!flag && item != Py_False)and if this returns true, then we return and only in the other case we come towhich then means that
a.
!flagis false which means thatflagis true which means thatitem == PY_TRUEwhich doesn't have to be decrementedb.
item == Py_FALSEwhich doesn't have to be decrementedc. both
(This was not tested, but I'm pretty sure from looking at the code, but please correct me if I'm mistaken)