Commit a4b5f9e
authored
feat(lambda-rs): Add policy to control the event loops control-flow (#182)
## Summary
Add an opt-in, configurable winit event loop control-flow policy so apps
that don’t need continuous rendering (tools/editors) can avoid
`ControlFlow::Poll` and reduce CPU/power usage when idle.
## Related Issues
- Resolves #98
## Changes
- Add `EventLoopPolicy` (`Poll`, `Wait`, `WaitUntil { target_fps }`) to
the winit wrapper and implement `Loop::run_forever_with_policy(...)`.
- Add `ApplicationRuntimeBuilder::with_event_loop_policy(...)` (defaults
to `Poll` for backwards compatibility) and wire it into
`ApplicationRuntime` execution.
- Re-export `EventLoopPolicy` from `lambda::runtimes` for easy
consumption.
- Update docs + minimal example to demonstrate `EventLoopPolicy::Wait`
for event-driven apps.
- Fix nightly clippy `never_loop` lint failure by removing an
unnecessary `return` inside an iterator adapter closure.
## Type of Change
- [ ] Bug fix (non-breaking change that fixes an issue)
- [x] Feature (non-breaking change that adds functionality)
- [ ] Breaking change (fix or feature that would cause existing
functionality to change)
- [x] Documentation (updates to docs, specs, tutorials, or comments)
- [ ] Refactor (code change that neither fixes a bug nor adds a feature)
- [x] Performance (change that improves performance)
- [ ] Test (adding or updating tests)
- [ ] Build/CI (changes to build process or CI configuration)
## Affected Crates
- [x] `lambda-rs`
- [x] `lambda-rs-platform`
- [ ] `lambda-rs-args`
- [ ] `lambda-rs-logging`
- [ ] Other:
## Checklist
- [x] Code follows the repository style guidelines (`cargo +nightly fmt
--all`)
- [x] Code passes clippy (`cargo clippy --workspace --all-targets -- -D
warnings`)
- [x] Tests pass (`cargo test --workspace`)
- [x] New code includes appropriate documentation
- [x] Public API changes are documented
- [ ] Breaking changes are noted in this PR description
## Testing
**Commands run:**
```bash
cargo +nightly fmt --all
rustup run nightly cargo clippy --workspace --all-targets -- -D warnings
cargo test --workspace
```
**Manual verification steps (if applicable):**
1. (Optional) Run an example app and verify CPU usage drops when idle
with `EventLoopPolicy::Wait`.
## Screenshots/Recordings
N/A
## Platform Testing
- [x] macOS
- [ ] Windows
- [ ] Linux
## Additional Notes
- Default remains `Poll` to avoid behavior changes for existing
applications unless they opt in.
- `WaitUntil` is best-effort wakeup scheduling (control-flow only), not
frame pacing/vsync.6 files changed
Lines changed: 398 additions & 245 deletions
File tree
- crates
- lambda-rs-platform/src/winit
- lambda-rs
- examples
- src
- render
- runtimes
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1 | 1 | | |
2 | 2 | | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
3 | 8 | | |
4 | 9 | | |
5 | 10 | | |
| |||
44 | 49 | | |
45 | 50 | | |
46 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
| 66 | + | |
| 67 | + | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
| 83 | + | |
| 84 | + | |
| 85 | + | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
47 | 96 | | |
48 | 97 | | |
49 | 98 | | |
| |||
228 | 277 | | |
229 | 278 | | |
230 | 279 | | |
231 | | - | |
| 280 | + | |
232 | 281 | | |
233 | 282 | | |
234 | 283 | | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
| 301 | + | |
| 302 | + | |
| 303 | + | |
235 | 304 | | |
236 | 305 | | |
237 | 306 | | |
238 | | - | |
| 307 | + | |
| 308 | + | |
| 309 | + | |
| 310 | + | |
| 311 | + | |
| 312 | + | |
| 313 | + | |
| 314 | + | |
| 315 | + | |
| 316 | + | |
| 317 | + | |
| 318 | + | |
| 319 | + | |
| 320 | + | |
| 321 | + | |
| 322 | + | |
| 323 | + | |
| 324 | + | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
| 329 | + | |
| 330 | + | |
| 331 | + | |
239 | 332 | | |
240 | 333 | | |
241 | 334 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
20 | 19 | | |
21 | | - | |
22 | | - | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
23 | 25 | | |
24 | 26 | | |
25 | 27 | | |
26 | 28 | | |
| 29 | + | |
| 30 | + | |
27 | 31 | | |
28 | 32 | | |
29 | 33 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
7 | 7 | | |
8 | 8 | | |
9 | 9 | | |
10 | | - | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
11 | 14 | | |
12 | 15 | | |
13 | 16 | | |
14 | 17 | | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
17 | 21 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
574 | 574 | | |
575 | 575 | | |
576 | 576 | | |
577 | | - | |
| 577 | + | |
578 | 578 | | |
579 | 579 | | |
580 | 580 | | |
581 | 581 | | |
582 | 582 | | |
583 | 583 | | |
584 | | - | |
| 584 | + | |
585 | 585 | | |
586 | 586 | | |
587 | 587 | | |
| |||
0 commit comments