Config: expose style traversal thread count#2
Closed
HenriqueAnzoategui wants to merge 1 commit into
Closed
Conversation
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).
c63fe55 to
e3b4d64
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds an additive
style_thread_count: Option<i32>field toConfigso callers can disable stylo's parallel style traversal when invokingrenderconcurrently 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-threadAtomicRefCellsharing caches borrowed mutably for each traversal's lifetime, and a second arrival panics withalready mutably borrowed. This bites pretty much any embedder drivingrender()concurrently — servers rendering HTML per request, batch pre-renderers, even hyper-render's own integration test suite (see the--test-threads=1workaround in PR 3's test summary).None(default) preserves the historical auto-thread behaviour. PassingSome(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.rspub style_thread_count: Option<i32>field onConfigwith full rustdoc covering the rationale and the one-shotSTYLE_THREAD_POOLinitialisation gotcha.pub fn style_thread_count(mut self, count: i32) -> Selfwith doctest.src/lib.rs—create_documentplumbsconfig.style_thread_countintoDocumentConfig.stylo_thread_count(blitz-side field name).Compatibility
Fully additive: new field on a struct that already derives
Default, new builder method that defaults toNone. Every existing caller is unaffected.Tests
cargo test --all-features✓ once the underlying blitz field is available.Related work
stylo_thread_countfield (dioxuslabs/blitz#436). Together they let hyper-render callers configure stylo's parallel traversal behaviour without taking a direct dep on stylo internals.