Can we make Initial UI creation/rendering faster in GTK3?

I am developing GTK3 application in Linux using C style APIs.

Our application requires a complex, multi-windowed interface and must deliver a very fast, responsive experience.

As a performance test, I built a sample app that creates three windows, each containing 500 GtkEntry controls (with each GtkEntry assigned 35 different properties such as text, styling, layout, etc). Only two of these properties are strings; the rest cover appearance, layout, and behaviour.

Code flow:

const int NUM_WIDGETS = 500;

void create_window_and_all_widgets () 
{    
    GtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Retained vs Immediate Mode");
    gtk_window_set_default_size(GTK_WINDOW(window), 1000, 600);
    g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
    
    GtkWidget* scrolled = gtk_scrolled_window_new(NULL, NULL);
    gtk_container_add(GTK_CONTAINER(window), scrolled);
    
    GtkWidget* fixed = gtk_fixed_new();
    gtk_container_add(GTK_CONTAINER(scrolled), fixed);
    
    int y = 50;
    for (int i = 0; i < NUM_WIDGETS; ++i) {
        GtkWidget* entry = gtk_entry_new();
        apply_all_props (entry, i);         // Apply properties (around 35 props)
        gtk_fixed_put(GTK_FIXED(fixed), entry, 10, y);
        y += 30;
    }

    gtk_widget_show_all(window);
}

int main(int argc, char* argv[]) {
    
    auto start = std::chrono::high_resolution_clock::now();

    gtk_init(&argc, &argv);
        
    create_window_and_all_widgets ();
    create_window_and_all_widgets ();
    create_window_and_all_widgets ();
    
    auto end = std::chrono::high_resolution_clock::now();
    std::cout << "Creation took "
    << std::chrono::duration_cast<std::chrono::microseconds>(end - start).count()
    << " microseconds\n";
    
    gtk_main();
    
    return 0;
}

Creating these 1,500 GtkEntry (across 3 windows) and applying their properties takes around 200-250 milliseconds.

Can I reduce this time further? If yes, what strategies or optimizations can I use, especially for large complex windows with lots of controls and frequent property updates?

P.S.: I can share my POC project if needed for more detailed analysis.

Why not use GTK4?

It would help GTK devs if you can provide more information on what you’re trying to do here. Refer XY Problem.

Hi,

Are all these 500 entries all visible at once in the window, or do you need to scroll to see some of them?
A typical optimization strategy is to only create the visible ones at startup, then the others on demand when scrolling.

1 Like

We initially chose GTK3 about two years ago because of its stability and better support compared to GTK4. We’re open to migrating to GTK4, but that decision will depend on how well it aligns with our use cases after evaluation.

I’m aiming to reduce the time it takes to create the initial UI as much as possible. The application I’m working on is a multi-window business app with numerous UI elements in each window. When the user launches the app, all windows should appear instantly with their content, without any noticeable delay.

Right now, I’m testing with 500 GtkEntry elements, but in reality, there will be a variety of different UI elements.

My main question is whether it’s possible to decrease the time required to load three windows with their content to under the current time of 200-250 milliseconds.

I’ve used 500 entries as a test example, but in reality, there will be various types of UI elements, such as buttons, dropdowns, tables, and more. However, all these elements will need to be visible on the screen.

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.