Skip to content

Config: expose style traversal thread count#2

Closed
HenriqueAnzoategui wants to merge 1 commit into
thomasmost:mainfrom
Kigo-Digital:kigo/stylo-thread-config
Closed

Config: expose style traversal thread count#2
HenriqueAnzoategui wants to merge 1 commit into
thomasmost:mainfrom
Kigo-Digital:kigo/stylo-thread-config

Conversation

@HenriqueAnzoategui
Copy link
Copy Markdown

Summary

Adds an additive style_thread_count: Option<i32> field to Config so callers can disable stylo's parallel style traversal when invoking render concurrently from multiple OS threads.

Without this, two concurrent renders share stylo's process-global STYLE_THREAD_POOL (initialised by blitz). Rayon workers in that pool hold per-thread AtomicRefCell sharing caches borrowed mutably for each traversal's lifetime, and a second arrival panics with already mutably borrowed. This bites pretty much any embedder driving render() concurrently — servers rendering HTML per request, batch pre-renderers, even hyper-render's own integration test suite (see the --test-threads=1 workaround in PR 3's test summary).

None (default) preserves the historical auto-thread behaviour. Passing Some(1) keeps style work on the calling thread, where the thread-local cache is uniquely owned. Per-render parallelism within stylo is negligible at typical hyper-render document sizes; the real-world tradeoff is a small per-render latency bump in exchange for safe concurrency across renders.

Changes

  • src/config.rs
    • New pub style_thread_count: Option<i32> field on Config with full rustdoc covering the rationale and the one-shot STYLE_THREAD_POOL initialisation gotcha.
    • New builder method pub fn style_thread_count(mut self, count: i32) -> Self with doctest.
  • src/lib.rscreate_document plumbs config.style_thread_count into DocumentConfig.stylo_thread_count (blitz-side field name).

Compatibility

Fully additive: new field on a struct that already derives Default, new builder method that defaults to None. Every existing caller is unaffected.

Tests

  • 1 doctest on the new builder method asserting the field round-trips.
  • cargo test --all-features ✓ once the underlying blitz field is available.

Related work

  • This PR is the second of a two-part series; the first half landed blitz's stylo_thread_count field (dioxuslabs/blitz#436). Together they let hyper-render callers configure stylo's parallel traversal behaviour without taking a direct dep on stylo internals.

@HenriqueAnzoategui HenriqueAnzoategui marked this pull request as draft May 12, 2026 18:08
Forwards the new `DocumentConfig::stylo_thread_count` field from blitz
through hyper-render's `Config` as `style_thread_count`, so callers can
disable parallel style traversal when invoking `render` concurrently
from multiple OS threads. The name is engine-neutral at hyper-render's
abstraction layer; the field passes through to blitz's stylo-specific
knob underneath.

Without this, two concurrent renders share stylo's process-global
`STYLE_THREAD_POOL`; rayon workers in that pool hold per-thread
`AtomicRefCell` sharing caches borrowed mutably for each traversal's
lifetime, and a second arrival panics with `already mutably borrowed`.
Passing `Some(1)` keeps style work on the calling thread, where the
thread-local cache is uniquely owned.

`None` (default) preserves the historical auto-thread behaviour, so
existing callers are unaffected.

Depends on the matching `stylo_thread_count` field landing in blitz
(dioxuslabs/blitz#TBD).
@HenriqueAnzoategui HenriqueAnzoategui force-pushed the kigo/stylo-thread-config branch from c63fe55 to e3b4d64 Compare May 12, 2026 18:27
@HenriqueAnzoategui HenriqueAnzoategui deleted the kigo/stylo-thread-config branch May 19, 2026 17:24
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.

1 participant