Mixing libraries

Let us try blogging again. If you search L.B.A. Tribute news you can find them at coffemonsters.com Here we will be focusing on more technical stuff.  

These days I'm tracking some delay in the processing of interaction between my UI (Qt) and Backend (custom code). Generally still far from resolving issues but slowly digging through problems. One of them hit me as an interesting one: QtTimer.

I'm using them because they are the most efficient way of injecting some processing into Qt. If this claim is true I'm not sure but they for sure work better than anything I tested so far. 

Generally, my whole tooling is based on multiple processes that communicate with each other. I got a little bit more into the details in the presentation that I did recently:


This setup result that I have multiple Qt event queues processing at the same time. One in the base process and one in the sub-process. It is really important, that they are processed efficiently because I discovered the hard way that if one of them lags other can lag too. Issue that on top of the Qt events I need to process in equal intervals some other tasks.

I thought originally that I would be processing events for some time and then move to additional ones:

    QApplication app; 
    while(!isTerminated()) 
    
        app.processEvents(QEventLoop::AllEvents, 100);
        apiEditorMainLoop(); 
    }

This turned out to be pretty inefficient as processing events with a timelimit is in Qt an active wait. Processes that did not have a lot happening were eating my CPU powers like kid candies :/ I dig a little bit and a better option would be to just allow Qt to process all system events without any timer. Then. Qt can enter wait on object which is more CPU efficient. 

    QApplication app; 
    QTimer timer;
    timer.setInterval(1000/60);
    timer.callOnTimeout([&]() {apiEditorMainLoop();});
    timer.start();
    app.exec();

And it turned out it was as now I achieved a nice 0.01 CPU use for the majority of apps. But today digging around in the profile I discovered an issue:


What happens is that in apiEditorMainLoop() I'm using SDL_PollEvent(...) which leads to nested calls. 

From what I understand QtTimer uses system timers that can be triggered while processing events using SDL. But I of course can be wrong here. 

Still, it is interesting for me how sometimes while mixing some libraries we get this weird stuff. 

Comments

Popular posts from this blog

Query commands execution

W.U. 0x21

WRE