Skip to content

fix(text): share Linux fontconfig collection process-wide and add prewarm_system_fonts - #2660

Merged
Hona merged 1 commit into
devfrom
fix/linux-fontconfig-shared-prewarm
Nov 27, 2026
Merged

Hona merged 1 commit into
devfrom
fix/linux-fontconfig-shared-prewarm

Conversation

@Hona

@Hona Hona commented Nov 27, 2026

Copy link
Copy Markdown
Member

Fixes #2657.

Problem

On Linux/Unix, crates/rune-text/src/fonts/system_fonts/fontconfig.rs stored fontique::Collection in a thread_local!, so every thread that hit a character absent from bundled fonts built its own fontconfig collection (~240–400 ms on the UI/layout thread) and apps had no way to warm fontconfig ahead of time on a background thread.

Changes

  • Process-wide shared system collection (WarmSlot<Collection>): Replaced the thread_local! fontconfig collection in crates/rune-text/src/fonts/system_fonts/fontconfig.rs with a single process-wide OnceLock<Mutex<Collection>> (WarmSlot in crates/rune-text/src/fonts/system_fonts/warm.rs). Concurrent callers coalesce onto one initialization and share the resulting collection and caches across all threads.
  • Public background warm-up (rune::text::prewarm_system_fonts()): Added rune_text::prewarm_system_fonts() (re-exported as rune::text::prewarm_system_fonts()). Calling it from main, on_ready, or any thread returns immediately and builds fontconfig's shared collection on a background thread ("rune-font-prewarm"). Repeated calls are idempotent; layout waiting on an in-flight warm-up waits for that single build rather than starting a second one. Respects RUNE_SYSTEM_FONTS=off and set_system_fonts(false) (no thread spawned, no fontconfig init), and is a no-op on macOS/iOS, Windows, Android, and wasm32.
  • Skip empty fontconfig queries: Early-return in fontconfig::family_files when names is empty and in fontconfig::fallback_family_files when no non-Common/Inherited/Unknown scripts are present.
  • Tests & docs: Added unit tests in crates/rune-text/src/fonts/system_fonts/warm_tests.rs covering cross-thread sharing, non-blocking background warm-up, single-build coalescing, disabled-switch gating, and Collection sharing; extended crates/rune-text/tests/no_system_fonts.rs; updated crates/rune/README.md and added a changelog entry.

Verification

  • Verified locally on Windows:
    • cargo test -p rune-text --lib system_fonts (33 passed, including 5 new warm tests)
    • cargo test -p rune-text --test no_system_fonts (1 passed)
    • cargo check -p rune --lib
    • cargo check -p rune-text --target wasm32-unknown-unknown
    • Zero clippy warnings in touched files.
  • Not verified locally on Linux hardware: Linux fontconfig compilation, Linux-only test fontconfig_empty_queries_do_not_initialize_or_fail, and real Linux frame-timing measurements rely on Linux CI / real Linux hosts.

@Hona
Hona merged commit a146fdc into dev Nov 27, 2026
@Hona
Hona deleted the fix/linux-fontconfig-shared-prewarm branch November 27, 2026 22:16
pascalandr added a commit to NeuralNomadsAI/rune that referenced this pull request Nov 27, 2026
Upstream merged the first Android slice (anomalyco#2662, closing anomalyco#2647): the winit
activity feature, the getloadavg gate and an android workflow. Taken from
upstream: runq.rs, the Android target section of rune's Cargo.toml (the
fork's JNI, NDK and AccessKit dependencies now sit in it), android.yml and
the changelog entry; the fork's own S0 entry goes.

Also from upstream since the last merge:
- Cx::touch_controls and hover_none read the host's primary pointer
  (anomalyco#2638). The fork's cfg(android) constants go; the Android LayerHost
  calls set_touch_controls(true), as the iOS one does.
- rune-text's prewarm_system_fonts (anomalyco#2660): Android's backend answers it
  with nothing to build ahead.
- rav1d without assembly (anomalyco#2641): an x86_64 library with avif links
  without -Wl,-Bsymbolic, so ANDROID.md's note about it goes.

Kept over upstream in android.yml: the android/** push trigger and the apk
job, which builds the Kotlin host with the example.

Checked: clippy for both Android targets (let_underscore_must_use allowed,
as rune-core fails it upstream), an x86_64 cdylib with avif links,
check-wasm, cargo check, file-size, rune lib tests 4087 passed with the 4
failures upstream dev has on Windows (and one more that passes alone).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Linux: the first character the bundled fonts lack blocks the thread laying out text for 240–400 ms (fontconfig collection built there, per thread)

1 participant