Skip to content

BUG: Too many styles can lead to compile-time memory leaks #1777

@wyhaya

Description

@wyhaya
xilem = { git = "https://github.com/linebender/xilem.git" }
# or
xilem = "0.4.0"
use xilem::style::Style;
use xilem::view::{label, sized_box};
use xilem::{EventLoop, WidgetView, WindowOptions, Xilem};

fn app_logic(_state: &mut ()) -> impl WidgetView<()> + use<> {
    sized_box(label("Hello"))
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
        .padding(1.0)
}

fn main() {
    let app = Xilem::new_simple((), app_logic, WindowOptions::new("title"));
    app.run_in(EventLoop::with_user_event()).unwrap();
}
cargo run
┌──────────────┬─────────┬──────────┬─────────┐
│ Process Name │ % CPU   │ Memory   │ Threads │
├──────────────┼─────────┼──────────┼─────────┤
│ rustc        │ 100.0   │ 14.59 GB │ 4       │
└──────────────┴─────────┴──────────┴─────────┘

This example failed to compile on my computer; rustc would consume tens of gigabytes of memory and eventually fail.
However, if you try reducing the use of .padding, it compiles very easily.

# macOS / Linux
rustc 1.95.0 (59807616e 2026-04-14)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions