U0013 egui-repaint-every-frame¶
Rule: UI code asks for a repaint when something changed, not on every frame.
| Code | U0013 (stable, never reused) |
| Id | egui-repaint-every-frame |
| Category | egui |
| Source | spirit_level |
| Fix | by hand |
Level per tier¶
| Tier | Level | Reason |
|---|---|---|
| small | off | |
| small-workspace | off | |
| medium | off | |
| big | off | |
| ai | off | |
| embedded | off | |
| ui | off | |
| egui | warn |
an unconditional repaint request keeps the app drawing at full rate and burns a core while idle |
| units-strict | off | |
| units-paranoid | off |
Parameters¶
| Name | Type | Default | Meaning |
|---|---|---|---|
calls |
list of strings | ["request_repaint"] |
methods that ask for the next frame now |
after-calls |
list of strings | ["request_repaint_after"] |
methods that ask for a frame after a delay |
ui-types |
list of strings | ["Ui", "Frame"] |
parameter types of a function that runs every frame |
interval-ms-min |
integer | 100 |
a delay below which an unconditional repaint request is a busy loop |
toolkits |
list of strings | ["egui", "eframe", "iced", "slint", "gtk4", "relm4", "dioxus", "leptos", "yew", "floem", "xilem", "makepad-widgets"] |
UI toolkits: a crate that depends on one directly is a UI crate, unless the crate map says ui = false |
Why¶
egui redraws when input arrives or when something asks for it. A request_repaint() that runs on every frame asks for the next frame each time: the app draws at full rate while idle, burns a core and drains a battery. A request_repaint_after with a delay of a few milliseconds is the same loop.
The lint reports, in a function that takes a ui-types parameter (Ui, Frame: it draws a frame, so it runs every frame; a function that takes only the Context is often called once, on an event), a statement of the function body itself (not inside a condition or a closure) that calls one of calls without arguments, or one of after-calls with a Duration::from_* literal below interval-ms-min. Findings are estimates.
How to fix¶
Ask for a repaint where something changed: the worker that has news calls ctx.request_repaint() (vhrd_egui: ve_app::Repainter), an animation asks while it runs, a clock asks with request_repaint_after for its next tick.
Configure¶
[lints.egui-repaint-every-frame]
level = "deny"
calls = ["request_repaint"]
after-calls = ["request_repaint_after"]
ui-types = ["Ui", "Frame"]
interval-ms-min = 100
toolkits = ["egui", "eframe", "iced", "slint", "gtk4", "relm4", "dioxus", "leptos", "yew", "floem", "xilem", "makepad-widgets"]
reason = "why this project wants it at this level"
Allow one finding in the code with // spirit-level: allow(egui-repaint-every-frame) <reason> (waivers); the code works there too, as in [lints.U0013].