[GH-ISSUE #1751] horizon-threads: lower helper threads on Android too (target_os = "android" is not "linux") #530

Closed
opened 2026-11-02 15:39:48 +07:00 by bsakaguchi · 1 comment
Owner

Originally created by @feeldev12 on GitHub (Oct 25, 2026).
Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1751

Hi! I'm porting Horizon to Android. I know Android isn't a target here; this is a one-line cfg that only matters to Android builds, and it doesn't change Linux, macOS or Windows.

What

horizon_threads::behind(), the BEHIND constant and the libc dependency are gated on cfg(target_os = "linux"). Rust gives Android its own target_os = "android", so on an Android build behind_server() returns false and the world generation, lighting and meshing workers keep the render thread's priority. The same kernel calls work there (setpriority, then SCHED_IDLE), and an app may lower its own threads. The change is any(target_os = "linux", target_os = "android") on those gates, in the tests too.

Measured (Dimensity 8300 phone, render distance 12, 60 FPS, joined to a local server, four fresh worlds alternating, same seed and route)

With --spikes, slow frames used to spend 14–18 ms on average, and up to 314 ms, in streaming::update's meshing stage. That turned out to be the render thread waiting for a core right after it woke the workers: submitting the jobs under one lock changed nothing. With the workers 10 nice levels behind (the render thread runs at -10 on Android, the workers then at 0):

  • meshing stage in slow frames: avg 13.6–17.7 → 1.9–4.4 ms, max 141–314 → 56–128 ms
  • update_world in slow frames: avg 41–61 → 26–34 ms
  • frames over 100 ms per run: 43–82 → 27–39; worst frame 472–1784 → 296–511 ms

Happy to open the PR if you'd take it.

Originally created by @feeldev12 on GitHub (Oct 25, 2026). Original GitHub issue: https://github.com/horizon-rust/horizon/issues/1751 Hi! I'm porting Horizon to Android. I know Android isn't a target here; this is a one-line `cfg` that only matters to Android builds, and it doesn't change Linux, macOS or Windows. **What** `horizon_threads::behind()`, the `BEHIND` constant and the `libc` dependency are gated on `cfg(target_os = "linux")`. Rust gives Android its own `target_os = "android"`, so on an Android build `behind_server()` returns `false` and the world generation, lighting and meshing workers keep the render thread's priority. The same kernel calls work there (`setpriority`, then `SCHED_IDLE`), and an app may lower its own threads. The change is `any(target_os = "linux", target_os = "android")` on those gates, in the tests too. **Measured** (Dimensity 8300 phone, render distance 12, 60 FPS, joined to a local server, four fresh worlds alternating, same seed and route) With `--spikes`, slow frames used to spend 14–18 ms on average, and up to 314 ms, in `streaming::update`'s meshing stage. That turned out to be the render thread waiting for a core right after it woke the workers: submitting the jobs under one lock changed nothing. With the workers 10 nice levels behind (the render thread runs at -10 on Android, the workers then at 0): - meshing stage in slow frames: avg 13.6–17.7 → 1.9–4.4 ms, max 141–314 → 56–128 ms - `update_world` in slow frames: avg 41–61 → 26–34 ms - frames over 100 ms per run: 43–82 → 27–39; worst frame 472–1784 → 296–511 ms Happy to open the PR if you'd take it.
Author
Owner

@rdbtCVS commented on GitHub (Oct 25, 2026):

🤖 Agent: I am rdbtCVS’s AI agent (Codex), taking this on. I will extend the existing helper-thread scheduling gates to Android, keep the current nice +10 / SCHED_IDLE behavior, and validate the targeted crate and repository self-check.

<!-- gh-comment-id:6403081065 --> @rdbtCVS commented on GitHub (Oct 25, 2026): 🤖 Agent: I am rdbtCVS’s AI agent (Codex), taking this on. I will extend the existing helper-thread scheduling gates to Android, keep the current nice +10 / SCHED_IDLE behavior, and validate the targeted crate and repository self-check.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
horizon-rust/horizon#530
No description provided.