Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QML optimization #4339

Merged
merged 2 commits into from
Oct 9, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 2 additions & 5 deletions res/qml/Deck.qml
Original file line number Diff line number Diff line change
Expand Up @@ -185,18 +185,15 @@ Item {

let minutes = Math.floor(positionSeconds / 60);
let seconds = positionSeconds - (minutes * 60);
let centiseconds = Math.trunc((seconds - Math.trunc(seconds)) * 100);
const deciseconds = Math.trunc((seconds - Math.trunc(seconds)) * 10);
seconds = Math.trunc(seconds);
if (minutes < 10)
minutes = "0" + minutes;

if (seconds < 10)
seconds = "0" + seconds;

if (centiseconds < 10)
centiseconds = "0" + centiseconds;

return minutes + ':' + seconds + "." + centiseconds;
return minutes + ':' + seconds + "." + deciseconds;
}

Mixxx.ControlProxy {
Expand Down
6 changes: 5 additions & 1 deletion res/qml/Mixxx/Controls/WaveformOverviewMarker.qml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Mixxx 0.1 as Mixxx
import QtQuick 2.12
import QtQuick.Shapes 1.12
import QtQuick.Window 2.12
Swiftb0y marked this conversation as resolved.
Show resolved Hide resolved

Item {
id: root
Expand Down Expand Up @@ -42,7 +43,10 @@ Item {

group: root.group
key: root.key
onValueChanged: marker.x = parent.width * value
onValueChanged: {
// Math.round saves tons of CPU by avoiding redrawing for fractional pixel positions.
marker.x = Math.round(parent.width * value * Screen.devicePixelRatio) / Screen.devicePixelRatio;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

won't the divide make the position fractional again?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but only for fractional logical pixels that correspond to real display pixels. So for a scale factor of 2, updates are done for every 0.5 logical pixels, or every real display pixel, but not extremely tiny fractions in between.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, so I guess the speedup comes from the fact that Qt doesn't have to do anti aliasing?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That doesn't make sense either though.

This feels like it should not be something programming QML should have to concern themselves with. So I feel like this is bug in Qt?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know, but I know that this little change saves a lot of CPU 🤷

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mhmm the only other idea I have is that the COs value changed multiple times per frame so the callback is also executed quite often. Since the position is always slightly different, the return value is also different. When rounding we always return the same value in the same pixel, so we often return the same value which enables Qt to do some caching optimization (so only doing work when the value actually changes).

}
}

}