Skip to content

use native c++ construction of QPixmap from QImage#3208

Merged
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:no-pixmap-constructor
Jan 6, 2025
Merged

use native c++ construction of QPixmap from QImage#3208
j9ac9k merged 1 commit intopyqtgraph:masterfrom
pijyoi:no-pixmap-constructor

Conversation

@pijyoi
Copy link
Copy Markdown
Contributor

@pijyoi pijyoi commented Dec 30, 2024

There is one instance in the pyqtgraph library where a QPixmap is created from a QImage via QPixmap's "constructor".
Except that C++ Qt doesn't have such a constructor. Some digging shows that this "constructor" is actually an emulation by the various Python Qt bindings. This emulation can be measured to be very slightly slower than calling the official conversion API: QPixmap::fromImage

from time import perf_counter
from PySide6 import QtCore, QtGui

app = QtGui.QGuiApplication([])

qimg = QtGui.QImage(100, 100, QtGui.QImage.Format.Format_ARGB32_Premultiplied)
qimg.fill(QtCore.Qt.GlobalColor.transparent)

niters = 10_000

t0 = perf_counter()
for _ in range(niters):
    px = QtGui.QPixmap(qimg)
t1 = perf_counter()
print(t1 - t0)

t0 = perf_counter()
for _ in range(niters):
    px = QtGui.QPixmap.fromImage(qimg)
t1 = perf_counter()
print(t1 - t0)

On PySide6:

0.016223200000240467
0.011742000000594999

On PyQt6

0.022723099999893748
0.007624599999871862

@j9ac9k
Copy link
Copy Markdown
Member

j9ac9k commented Jan 6, 2025

Love these gimmie performance improvements. Thanks for the PR @pijyoi

@j9ac9k j9ac9k merged commit 378f21b into pyqtgraph:master Jan 6, 2025
@pijyoi pijyoi deleted the no-pixmap-constructor branch January 6, 2025 11:25
j9ac9k pushed a commit to j9ac9k/pyqtgraph that referenced this pull request Mar 25, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants