PDA

View Full Version : QtWebKit + Flash performance, Qt4 vs. Qt5



goffioul
24th September 2013, 00:23
I'm currently evaluating and comparing performances of QWebView and QGraphicsWebView in Qt4 and Qt5 when playing flash content, like Youtube video. I'm using a naive/simple test browser as the following:



#include <QApplication>
#include <QGraphicsView>
#include <QGraphicsWebView>
#include <QMainWindow>
#include <QWebSettings>
#include <QWebView>

class GraphicsBrowser : public QGraphicsView
{
public:
GraphicsBrowser (QWidget* parent)
: QGraphicsView (parent)
{
qDebug ("creating GraphicsBrowser...");

setScene (new QGraphicsScene (this));

setVerticalScrollBarPolicy(Qt::ScrollBarAlwaysOff) ;
setHorizontalScrollBarPolicy(Qt::ScrollBarAlwaysOf f);

m_webView = new QGraphicsWebView ();
scene ()->addItem (m_webView);
}

QGraphicsWebView* webView (void) { return m_webView; }

protected:
void resizeEvent (QResizeEvent *evt)
{
QGraphicsView::resizeEvent (evt);

QRect r = contentsRect ();

setSceneRect (0, 0, r.width (), r.height ());
m_webView->resize (r.width (), r.height ());
}

private:
QGraphicsWebView *m_webView;
};

int main (int argc, char **argv)
{
QApplication app (argc, argv);
QMainWindow win;
QString url ("http://slashdot.org");
bool useGraphicsView = false;

QWebSettings::globalSettings ()->setAttribute (QWebSettings::PluginsEnabled, true);
QWebSettings::globalSettings ()->setAttribute (QWebSettings::DeveloperExtrasEnabled, true);

for (int i = 1; i < argc; i++)
{
if (strcmp (argv[i], "-g") == 0)
useGraphicsView = true;
else
url = argv[i];
}

qDebug ("use QGraphicsView: %s", useGraphicsView ? "yes" : "no");
qDebug ("url: %s", url.toLatin1 ().data ());

if (useGraphicsView)
{
GraphicsBrowser *browser = new GraphicsBrowser (&win);
win.setCentralWidget (browser);
browser->webView ()->load (url);
}
else
{
QWebView *web = new QWebView (&win);
win.setCentralWidget (web);
web->load (url);
}

win.resize (1200, 800);
win.show ();

return app.exec ();
}


The main problem I noticed is that performances of the above code under Qt5 are much lower than Qt4, when using a simple QWebView playing a Youtuve video. When compiling the above code and playing a Youtube video through the "QWebView" path, it runs at about 25% CPU usage. Compiling the same code with Qt5 and using the same video makes it run at about 50% CPU. Also when comparing the QWebView and the QGraphicsWebView paths, in Qt4 QGraphicsWebView is twice as slow as QWebView (when playing the same Youtube video), while there doesn't seem to be a difference under Qt5.

From what I know, I believe Qt4+QWebView is faster because the flash plugin is painting directly on screen, while QGraphicsWebView uses an internal buffer and does kinda software compositing. From the performance numbers, I'm wondering whether Qt5+QWebView is also using an internal buffer.

In any case, could anybody shed some light on why Qt5+QWebView shows such a performance degradation (I would have expected better performances actually). Am I doing something wrong and the naive implementation above is *not* the way to go?

System details:
OS: Linux, Fedora 18, up to date
Qt4: 4.8.4
QtWebKit: 2.3.2
Qt5/QtWebKit: 5.1.1


PS: for the record, I've also tried a QML-based simple implementation using QtQuick 2.0 and QtWebKit 3.0, and in that case, I have 2 processes, QtWebPluginProcess and QtWebProcess running at ~35% and ~25% respectively

goffioul
27th September 2013, 02:29
After looking into webkit code, it appears wmode=opaque is enforced in all cases when using Qt5 (unlike Qt4, where it's only enforced for non QWebView). This explains the performance degradation of Qt5+QWebView compared to Qt4+QWebView.