如何重現:不斷重繪8000個無形的項目,當鼠標區域也存在一個場景,會導致CPU佔用率過高
- 我的代碼運行
- 按住鼠標上出現
你會發現CPU使用率相當高,儘管它取決於你的硬件。在my PC它是20%(4個虛擬內核中的每一個都是5%)。
我給這家測試用例的動機:在我真正的應用程序我有很多的不可見(culled)項目,而剔除幫助了很多與CPU使用率,它並不能幫助像我一樣」 d期望。
我想知道爲什麼CPU使用率如此之高以及如何減少它。
我的代碼:
main.qml:
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 800
height: 500
MouseArea {
width: 1
height: 1
hoverEnabled: true
}
AnimatedItem {
anchors.centerIn: parent
width: 100
height: 100
}
Repeater {
model: 8000
Item {
opacity: 0
layer.enabled: true
width: 1
height: 1
}
}
}
AnimatedItem.qml:
import QtQuick 2.0
Rectangle {
id: root
color: "black"
property real rotAngle: 0
NumberAnimation on rotAngle {
from: 0
to: 360
loops: Animation.Infinite
running: true
duration: 500
}
transform: Rotation {
origin.x: root.width/2
origin.y: root.height/2
angle: root.rotAngle
}
}
我與QML探查,異形它這已經表明在QML中花費了微不足道的時間。所以我也用C++ profiler(CodeXL)進行了剖析。據報道,大部分時間都花在QSGRootNode::~QSGRootNode()
上,因爲它叫QSGNodeUpdater::isNodeBlocked(QSGNode*, QSGNode*) const
。我查看了Qt源代碼,但一直未能弄清楚爲什麼它甚至會調用前者。