Skip to content

wip: Add g_task_await()

Benjamin Otte requested to merge wip/otte/await into master

Recently while working on optimizing performance in GTK, it came up that we could really speed thins up if we had an equivalent to the Javascript await operator. I had a look at GTask today and found out that it seemed rather easy to implement, so I did a rough prototype to gather feedback.

I'll outline where this API would come in handy: When GTK creates a new window (including the first window on application startup), the main thread will do a lot of things to display this window. Many of these things are tasks where GTK knows that it will ultimately need the results, but it doesn't need the results quite yet. So it could spawn tasks in threads that run these operations.
However, the main thread requires this data to be available at some point in time or it cannot continue, so it needs to block waiting for the data. However, this is currently impossible.

A few examples:

  • Loading icons from the icon theme: GTK knows it will need those icons when the image is created and could start loading the PNG files right then, but it needs the GL texture of the decoded files when it blits the frame. However, size allocation and render node construction can happen while the PNGs get loaded.

  • Loading the CSS for the theme can be done during gtk_init() when the GtkSettings object is initialized. The parsed theme is only needed once the first window is shown and validates its CSS. In between the two points in time GTK can finish initialization, GApplication startup can happen and the initial GtkWindow can be loaded from .ui file. However, once that window is shown, the CSS file must be available.
    Various other themes (icon theme, cursor theme) fall in the same category.

Merge request reports