This if causes exact duplication of ~60 lines of code, because it claims it saves one iterator.
Can we just assume that's solely because in early 2000-s trolltech was fining people's salaries for using iterators and just de-duplicate it? Or should we benchmark this?
Or am I missing something? Were iterators really expensive back then? are they now?
[This `if`][1] causes exact duplication of ~60 lines of code, because it claims it saves one iterator.
Can we just assume that's solely because in early 2000-s trolltech was fining people's salaries for using iterators and just de-duplicate it? Or should we benchmark this?
Or am I missing something? Were iterators really expensive back then? are they now?
[1]: https://mirror.git.trinitydesktop.org/gitea/TDE/tqt3/src/commit/bd8bd100a41d205592a3c4d41c52617bfdeb602d/src/kernel/qobject.cpp#L2771
I reckon they decided to differentiate because most of the times one signal is connected to exactly one slot, so they were trying to save as much time as possible. Perhaps it was a remnant from Qt1/2 when computers were not as powerfull.
I think modern computers are fast enough and it would be good to simplify the code IMO
I reckon they decided to differentiate because most of the times one signal is connected to exactly one slot, so they were trying to save as much time as possible. Perhaps it was a remnant from Qt1/2 when computers were not as powerfull.
I think modern computers are fast enough and it would be good to simplify the code IMO
I haven't looked at the original code, but maybe we could use a macro to achieve the de-duplication? That way we can reuse code and avoid runtime costs?
I haven't looked at the original code, but maybe we could use a macro to achieve the de-duplication? That way we can reuse code and avoid runtime costs?
I think it is more likely that the original tqt3 iterator was subpar compared to modern iterator implementation. Or the extra time coud com
Anyway, even with the original tqt3 iterator, 700ms over 1 billion signal executions (without any real code in the receiver) would not have been a huge delay.
Looks like we can simplify the code with a bit of modern c++ :-)
> Thank c++ gods for c++11.
I think it is more likely that the original tqt3 iterator was subpar compared to modern iterator implementation. Or the extra time coud com
Anyway, even with the original tqt3 iterator, 700ms over 1 billion signal executions (without any real code in the receiver) would not have been a huge delay.
Looks like we can simplify the code with a bit of modern c++ :-)
I think it is more likely that the original tqt3 iterator was subpar compared to modern iterator implementation. Or the extra time coud com
The range-based for uses (almost) the same iterators under the hood. The actual difference is:
it technically uses TQPtrList<TQConnection>::Iterator instead of TQConnectionListIt, but the last one is solely a thin wrapper that should be optimized out.
it uses a different condition: ci != clist.end() instead of ci.current().
I haven't tested it, but I suspect that because of this the compiler should be able to produce a more branch-prediction-friendly code.
> I think it is more likely that the original tqt3 iterator was subpar compared to modern iterator implementation. Or the extra time coud com
The range-based `for` uses (almost) the same iterators under the hood. The actual difference is:
- it technically uses `TQPtrList<TQConnection>::Iterator` instead of `TQConnectionListIt`, but the last one is solely a thin wrapper that should be optimized out.
- it uses a different condition: `ci != clist.end()` instead of `ci.current()`.
I haven't tested it, but I suspect that because of this the compiler should be able to produce a more branch-prediction-friendly code.
This
if
causes exact duplication of ~60 lines of code, because it claims it saves one iterator.Can we just assume that's solely because in early 2000-s trolltech was fining people's salaries for using iterators and just de-duplicate it? Or should we benchmark this?
Or am I missing something? Were iterators really expensive back then? are they now?
I reckon they decided to differentiate because most of the times one signal is connected to exactly one slot, so they were trying to save as much time as possible. Perhaps it was a remnant from Qt1/2 when computers were not as powerfull.
I think modern computers are fast enough and it would be good to simplify the code IMO
I've actually already thrown together a quick benchmark yesterday just in case:
For five round of run, Results without the patch:
And with the patch:
If I didn't mess up my measurements, it seems I owe an apology to somebody in trolltech: this actually saves ~10% on a signal handling costs.
I still think it'd be nice to de-duplicate, but now I'd me more cautious about it.
I haven't looked at the original code, but maybe we could use a macro to achieve the de-duplication? That way we can reuse code and avoid runtime costs?
Actually, range-based
for
does some magic:And code runs even (marginally) faster than before:
Thank c++ gods for c++11.
I think it is more likely that the original tqt3 iterator was subpar compared to modern iterator implementation. Or the extra time coud com
Anyway, even with the original tqt3 iterator, 700ms over 1 billion signal executions (without any real code in the receiver) would not have been a huge delay.
Looks like we can simplify the code with a bit of modern c++ :-)
The range-based
for
uses (almost) the same iterators under the hood. The actual difference is:TQPtrList<TQConnection>::Iterator
instead ofTQConnectionListIt
, but the last one is solely a thin wrapper that should be optimized out.ci != clist.end()
instead ofci.current()
.I haven't tested it, but I suspect that because of this the compiler should be able to produce a more branch-prediction-friendly code.