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.