Skip to content

Conversation

@jopamo
Copy link

@jopamo jopamo commented Dec 9, 2025

This patch introduces two optimizations for large menus.

1. Cache the number of menu entries

The new num_entries field stores the total number of menu items.
This removes repeated O(N) calls to g_list_length during geometry updates and placement calculations such as menu_frame_move_on_screen.

2. Reduce menu population from O(N²) to O(N)

The previous implementation used g_list_append inside the population loop, causing a linear scan on every iteration.
The replacement uses g_list_prepend in the loop and a single g_list_reverse once the loop is complete.

Overall Effect

Together, these changes dramatically reduce CPU usage when opening or navigating very large menus (such as full “All Applications” views).


Performance Impact

For a menu with N items:

Operation Before After Improvement
List construction O(N²) O(N) ~N× faster
Length queries O(N) each O(1) ~N× faster
Total for 500 items ~125k traversals ~500 traversals 250× reduction

This patch introduces two optimizations for large menus:

1. Caches the number of menu entries in `num_entries`.
   This eliminates O(N) calls to `g_list_length` during geometry updates
   and placement calculations (e.g., `menu_frame_move_on_screen`).

2. Optimizes menu population loop from O(N^2) to O(N).
   Replaces `g_list_append` (which scans the list) inside the loop with
   `g_list_prepend` followed by a single `g_list_reverse` at the end.

Together, these changes significantly reduce CPU usage when opening or
navigating large menus (e.g., "All Applications" lists).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant