Skip to content

fix(memory): memory growth app side#97

Open
Times-Z wants to merge 2 commits intowayle-rs:masterfrom
Times-Z:fix/memory-leaks
Open

fix(memory): memory growth app side#97
Times-Z wants to merge 2 commits intowayle-rs:masterfrom
Times-Z:fix/memory-leaks

Conversation

@Times-Z
Copy link
Copy Markdown

@Times-Z Times-Z commented Apr 6, 2026

Objective

Resolve part of memory growth in the bar shell reported in issue #95, particularly when notifications and media player / systray activity are present
The investigation used heaptrack profiling across multiple runs (only in release mode) to isolate leaks and validate fixes

Solutions

Four targeted fixes addressed the major memory leak vectors in application code:

  1. Systray CSS Provider

    • Prevented repeatedly attaching the same CSS provider on every icon update
    • Added icon_color_provider_attached flag to SystrayItem to attach the provider only once
  2. Notification Icon Loading

    • Replaced full-size file icon loading with scaled texture loading for both popup cards (64px) and dropdown items (48px)
    • Added load_scaled_file_icon() helper using gdk_pixbuf::Pixbuf::from_file_at_scale + Texture::for_pixbuf
    • Added gdk-pixbuf workspace dependency
  3. Systray Icon Deduplication

    • Added IconSignature enum to track when icons have actually changed (vs. redundant updates)
    • update_icon() now compares signature and skips apply if unchanged
    • File-based systray icons are now loaded at scaled resolution instead of full-size
    • Clear image state before switching sources to help GObject release old texture references
  4. Bar Button Threshold Styling

    • Added deduplication check so CSS is reloaded only when ThresholdColors actually change
    • Prevents thousands of redundant gtk_css_provider_load_from_string calls per session from threshold polling

Validation results from heaptrack profiling:

  • Notification leak stacks (previously 13.11M) are no longer in top results
  • Systray repeated icon update leak path is no longer a growth source
  • Release builds validated after each fix

Remaining allocations (not actionable in this repo):

  • ~4.9M: GTK-internal texture caching in snapshot chain (no Rust frame)
  • ~4.3M: wayle_systray external crate icon pixmap D-Bus polling (zvariant/zbus allocations)
  • ~4.1M: Tracing initialization (intentional mem::forget(_guard) for log guard lifetime)

Test Plan

  • cargo check -p wayle-shell passes after each fix
  • cargo build --release -p wayle compiles successfully
  • heaptrack profiling validates leak removal across multiple sessions
  • Ensure cargo fmt and cargo clippy --workspace pass before merge

Remaining Work / Future Improvements

Leak Source Size Possible Action
wayle-systray icon pixmap polling ~4.25M Patch wayle-systray to debounce icon updates, or cache decoded pixmaps
GTK internal texture cache ~4.92M Profile GTK teardown or investigate custom texture lifecycle management
Tracing initialization ~4.10M Intentional (mem::forget for log guard); only fixable by removing logging
Pango/PangoFT2 font cache ~2.4M One-time cost during NetworkDropdown startup (acceptable)
PipeWire audio context ~430K One-time cost during CAVA module startup (acceptable)
sysinfo CPU temp file reads ~131K Consider caching temperature sensor reads in external crate

Fixes #95

@Times-Z Times-Z force-pushed the fix/memory-leaks branch 4 times, most recently from ac46855 to 1998795 Compare April 18, 2026 08:53
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Memory leak / RAM increasing

1 participant