forge
Explore
Log in

Don't you dare go Hollow

Recorded writes run inline at one reconstruction thread

Browse files at this commit

9258b06ef06aafb02f7db8154dc6bf91181908caAhmet Kaan GümüşParent: d5fa0c1
  • perf
    • recorded writes run inline at one reconstruction thread
Show full message
perf(av1): recorded writes run inline at one reconstruction thread

lane-wave1 step (ii), first half. Step (i) deferred every recorded
`ReconOp` to the end of its superblock, which cost +1.2% instructions and
+4.5% wall on 4K: the residual is written at parse and read back
cache-cold at replay.

`EC_AV1_RECON_THREADS` (default 1) now decides. At 1 the tile decoder
registers its three planes (`ReconInline`, dropped on every exit from the
tile including `?`) and every `push_*` performs its write on the spot,
with the residual still borrowed -- no record built, no queue, no
`to_vec`. Above 1 the queue behaves exactly as step (i) left it, for the
wavefront workers to come.

Measured against 69e1e50e, interleaved, same box: seg4k 607.12 -> 603.33 G
instructions:u (-0.62%), seg1080 189.81 -> 188.83 G (-0.52%); wall inside
the run-to-run noise on both (seg4k 30.5 vs 30.0-30.9 s, seg1080 9.2 vs
9.1-9.7 s). sha6 byte-exact on seg1080/seg4k/seg4k_lr/palette.
crates/ec-av1/src/decode.rsmodified+263 -37
@@ -85,6 +85,11 @@ pub(crate) struct FrameCtx {
85 /// The queue buffer [`flush_recon`] just drained, kept for its capacity85 /// The queue buffer [`flush_recon`] just drained, kept for its capacity
86 /// so a superblock's records do not regrow the vector from nothing.86 /// so a superblock's records do not regrow the vector from nothing.
87 pub(crate) recon_spare: std::cell::RefCell<Vec<ReconOp>>,87 pub(crate) recon_spare: std::cell::RefCell<Vec<ReconOp>>,
88+ /// lane-wave1 step (ii): the tile decoder's own planes, registered by
89+ /// [`ReconInline`] while reconstruction runs INLINE (one recon thread).
90+ /// `None` while the queue is in use (wavefront workers) and outside a
91+ /// tile. See [`push_op`].
92+ pub(crate) recon_planes: std::cell::Cell<Option<ReconPlanes>>,
88 }93 }
89 94
90 impl std::fmt::Debug for FrameCtx {95 impl std::fmt::Debug for FrameCtx {
@@ -144,6 +149,7 @@ impl FrameCtx {
144 grain_bit_depth: std::cell::Cell::new(8),149 grain_bit_depth: std::cell::Cell::new(8),
145 recon_ops: std::cell::RefCell::new(Vec::new()),150 recon_ops: std::cell::RefCell::new(Vec::new()),
146 recon_spare: std::cell::RefCell::new(Vec::new()),151 recon_spare: std::cell::RefCell::new(Vec::new()),
152+ recon_planes: std::cell::Cell::new(None),
147 }153 }
148 }154 }
149 }155 }
@@ -2081,10 +2087,142 @@ pub(crate) enum ReconOp {
2081 },2087 },
2082 }2088 }
2083 2089
2090+/// The three planes of the tile currently being decoded, as raw pointers.
2091+///
2092+/// corner-cut: at one reconstruction thread a recorded write must cost
2093+/// nothing -- deferring it to the end of the superblock is +1.2%
2094+/// instructions and +4.5% wall on 4K, because the residual is written at
2095+/// parse and read back cache-cold at replay. So the recorded op is performed
2096+/// at the push site instead, through the pointers the tile decoder registers
2097+/// once ([`ReconInline`]), which is the same thread, the same order and the
2098+/// same writes as before lane-wave1 -- but the `&mut PlaneBuf` the parse
2099+/// stack still holds aliases them, exactly the [`crate::par::Shared`]
2100+/// trade-off (Miri's stacked borrows would flag both). The upgrade path is
2101+/// threading the three planes down every `read_plane`/`read_inter_plane`
2102+/// call site (~40) so the push site owns the borrow it writes through.
2103+#[derive(Clone, Copy)]
2104+pub(crate) struct ReconPlanes(
2105+ *mut PlaneBuf<'static>,
2106+ *mut PlaneBuf<'static>,
2107+ *mut PlaneBuf<'static>,
2108+);
2109+
2110+// SAFETY: a `FrameCtx` sent to another thread (a frame worker, or
2111+// [`filter_ctx_copy`]) is always one whose guard is not installed, so the
2112+// value travelling is `None`; the pointers never leave the tile decoder's
2113+// own thread.
2114+#[allow(unsafe_code)]
2115+unsafe impl Send for ReconPlanes {}
2116+
2117+/// Registers the tile's planes for inline reconstruction and unregisters them
2118+/// on every exit from the tile decoder, including the `?` ones -- a stale
2119+/// pointer here would outlive the planes, since [`FrameCtx`] outlives the
2120+/// tile.
2121+pub(crate) struct ReconInline<'a>(&'a crate::decode::FrameCtx);
2122+
2123+#[allow(unsafe_code)]
2124+impl<'a> ReconInline<'a> {
2125+ /// Installs the guard for this tile when reconstruction is inline
2126+ /// (`EC_AV1_RECON_THREADS == 1`, the default); `None` hands every write
2127+ /// to the queue instead, for the wavefront workers to replay.
2128+ fn install(
2129+ fctx: &'a crate::decode::FrameCtx,
2130+ y: &mut PlaneBuf<'static>,
2131+ u: &mut PlaneBuf<'static>,
2132+ v: &mut PlaneBuf<'static>,
2133+ ) -> Option<Self> {
2134+ if crate::par::recon_threads() != 1 {
2135+ return None;
2136+ }
2137+ // SAFETY: the planes are locals of the tile decoder and outlive the
2138+ // guard, which is dropped on every exit from it (including `?`); see
2139+ // [`ReconPlanes`] for the aliasing trade-off.
2140+ let planes = ReconPlanes(
2141+ std::ptr::from_mut(y),
2142+ std::ptr::from_mut(u),
2143+ std::ptr::from_mut(v),
2144+ );
2145+ fctx.recon_planes.with(|c| c.set(Some(planes)));
2146+ Some(Self(fctx))
2147+ }
2148+}
2149+
2150+impl Drop for ReconInline<'_> {
2151+ fn drop(&mut self) {
2152+ self.0.recon_planes.with(|c| c.set(None));
2153+ }
2154+}
2155+
2156+#[allow(unsafe_code)]
2084 fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) {2157 fn push_op(fctx: &crate::decode::FrameCtx, op: ReconOp) {
2158+ if let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) {
2159+ // SAFETY: see [`ReconPlanes`] -- one thread, and the write is the one
2160+ // the parse site would have performed itself before lane-wave1.
2161+ unsafe { exec_op(op, &mut *y, &mut *u, &mut *v, fctx) };
2162+ return;
2163+ }
2085 fctx.recon_ops.with(|c| c.borrow_mut().push(op));2164 fctx.recon_ops.with(|c| c.borrow_mut().push(op));
2086 }2165 }
2087 2166
2167+/// Performs an intra write at its push site when the tile registered its
2168+/// planes for inline reconstruction ([`ReconPlanes`]); `false` when the
2169+/// caller must record it for the wavefront workers instead.
2170+#[allow(unsafe_code)]
2171+#[allow(clippy::too_many_arguments)]
2172+fn inline_intra(
2173+ plane: usize,
2174+ x: usize,
2175+ oy: usize,
2176+ bw: usize,
2177+ bh: usize,
2178+ rect: bool,
2179+ mode: usize,
2180+ angle_delta: i32,
2181+ reach: Reach,
2182+ residual: &[i32],
2183+ cfl: Option<(i32, CflSrc)>,
2184+ filter_intra: Option<usize>,
2185+ smooth_neighbor: bool,
2186+ fctx: &crate::decode::FrameCtx,
2187+) -> bool {
2188+ let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) else {
2189+ return false;
2190+ };
2191+ let pred = take_palette_pred(fctx);
2192+ // SAFETY: see [`ReconPlanes`].
2193+ unsafe {
2194+ exec_intra(
2195+ &mut *y, &mut *u, &mut *v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach,
2196+ residual, cfl, filter_intra, smooth_neighbor, pred, fctx,
2197+ );
2198+ }
2199+ true
2200+}
2201+
2202+/// [`inline_intra`] for a motion-compensated write.
2203+#[allow(unsafe_code)]
2204+#[allow(clippy::too_many_arguments)]
2205+fn inline_mc(
2206+ plane: usize,
2207+ x: usize,
2208+ oy: usize,
2209+ stride: usize,
2210+ w: usize,
2211+ h: usize,
2212+ prediction: &[u16],
2213+ residual: &[i32],
2214+ fctx: &crate::decode::FrameCtx,
2215+) -> bool {
2216+ let Some(ReconPlanes(y, u, v)) = fctx.recon_planes.with(std::cell::Cell::get) else {
2217+ return false;
2218+ };
2219+ // SAFETY: see [`ReconPlanes`].
2220+ unsafe {
2221+ exec_mc(&mut *y, &mut *u, &mut *v, plane, x, oy, stride, w, h, prediction, residual, fctx);
2222+ }
2223+ true
2224+}
2225+
2088 /// [`PlaneBuf::reconstruct`], recorded (lane-wave1 step (i)).2226 /// [`PlaneBuf::reconstruct`], recorded (lane-wave1 step (i)).
2089 #[allow(clippy::too_many_arguments)]2227 #[allow(clippy::too_many_arguments)]
2090 fn push_intra(2228 fn push_intra(
@@ -2100,6 +2238,12 @@ fn push_intra(
2100 filter_intra: Option<usize>,2238 filter_intra: Option<usize>,
2101 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,2239 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2102 ) {2240 ) {
2241+ if inline_intra(
2242+ plane, x, y, side, side, false, mode, angle_delta, reach, residual, cfl, filter_intra,
2243+ smooth_neighbor, fctx,
2244+ ) {
2245+ return;
2246+ }
2103 let pred = take_palette_pred(fctx);2247 let pred = take_palette_pred(fctx);
2104 push_op(fctx, ReconOp::Intra {2248 push_op(fctx, ReconOp::Intra {
2105 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,2249 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
@@ -2123,6 +2267,12 @@ fn push_intra_owned(
2123 filter_intra: Option<usize>,2267 filter_intra: Option<usize>,
2124 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,2268 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2125 ) {2269 ) {
2270+ if inline_intra(
2271+ plane, x, y, side, side, false, mode, angle_delta, reach, &residual, cfl, filter_intra,
2272+ smooth_neighbor, fctx,
2273+ ) {
2274+ return;
2275+ }
2126 let pred = take_palette_pred(fctx);2276 let pred = take_palette_pred(fctx);
2127 push_op(fctx, ReconOp::Intra {2277 push_op(fctx, ReconOp::Intra {
2128 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,2278 plane, x, y, bw: side, bh: side, rect: false, mode, angle_delta, reach,
@@ -2142,6 +2292,9 @@ fn push_mc_rect_owned(
2142 prediction: &[u16],2292 prediction: &[u16],
2143 residual: Vec<i32>, fctx: &crate::decode::FrameCtx,2293 residual: Vec<i32>, fctx: &crate::decode::FrameCtx,
2144 ) {2294 ) {
2295+ if inline_mc(plane, x, y, stride, w, h, prediction, &residual, fctx) {
2296+ return;
2297+ }
2145 push_op(fctx, ReconOp::Mc {2298 push_op(fctx, ReconOp::Mc {
2146 plane, x, y, stride, w, h, prediction: prediction.to_vec(), residual,2299 plane, x, y, stride, w, h, prediction: prediction.to_vec(), residual,
2147 });2300 });
@@ -2163,6 +2316,12 @@ fn push_intra_rect(
2163 filter_intra: Option<usize>,2316 filter_intra: Option<usize>,
2164 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,2317 smooth_neighbor: bool, fctx: &crate::decode::FrameCtx,
2165 ) {2318 ) {
2319+ if inline_intra(
2320+ plane, x, y, bw, bh, true, mode, angle_delta, reach, residual, cfl, filter_intra,
2321+ smooth_neighbor, fctx,
2322+ ) {
2323+ return;
2324+ }
2166 let pred = take_palette_pred(fctx);2325 let pred = take_palette_pred(fctx);
2167 push_op(fctx, ReconOp::Intra {2326 push_op(fctx, ReconOp::Intra {
2168 plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,2327 plane, x, y, bw, bh, rect: true, mode, angle_delta, reach,
@@ -2194,6 +2353,9 @@ fn push_mc_rect(
2194 prediction: &[u16],2353 prediction: &[u16],
2195 residual: &[i32], fctx: &crate::decode::FrameCtx,2354 residual: &[i32], fctx: &crate::decode::FrameCtx,
2196 ) {2355 ) {
2356+ if inline_mc(plane, x, y, stride, w, h, prediction, residual, fctx) {
2357+ return;
2358+ }
2197 push_op(fctx, ReconOp::Mc {2359 push_op(fctx, ReconOp::Mc {
2198 plane, x, y, stride, w, h,2360 plane, x, y, stride, w, h,
2199 prediction: prediction.to_vec(), residual: residual.to_vec(),2361 prediction: prediction.to_vec(), residual: residual.to_vec(),
@@ -2217,47 +2379,105 @@ fn flush_recon(
2217 let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));2379 let mut ops = fctx.recon_spare.with(|c| std::mem::take(&mut *c.borrow_mut()));
2218 fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));2380 fctx.recon_ops.with(|c| std::mem::swap(&mut *c.borrow_mut(), &mut ops));
2219 for op in ops.drain(..) {2381 for op in ops.drain(..) {
2220- match op {2382+ exec_op(op, y, u, v, fctx);
2221- ReconOp::Intra {
2222- plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
2223- filter_intra, smooth_neighbor, pred,
2224- } => {
2225- // The CfL AC signal is read HERE, off the luma this very
2226- // replay has already written for this block -- at parse time
2227- // it would have been the previous frame's samples.
2228- let ac = cfl.map(|(alpha, src)| {
2229- let sig = if src.rect {
2230- cfl_ac_q3_rect(&*y, src.px, src.py, src.bw, src.bh)
2231- } else {
2232- cfl_ac_q3(&*y, src.px, src.py, src.bw)
2233- };
2234- (alpha, sig)
2235- });
2236- let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
2237- let target: &mut PlaneBuf<'static> =
2238- match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2239- if rect {
2240- target.reconstruct_rect(
2241- x, oy, bw, bh, mode, angle_delta, reach, &residual, cfl, filter_intra,
2242- smooth_neighbor, pred, fctx,
2243- );
2244- } else {
2245- target.reconstruct(
2246- x, oy, bw, mode, angle_delta, reach, &residual, cfl, filter_intra,
2247- smooth_neighbor, pred, fctx,
2248- );
2249- }
2250- }
2251- ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {
2252- let target: &mut PlaneBuf<'static> =
2253- match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2254- target.reconstruct_mc_rect(x, oy, stride, w, h, &prediction, &residual, fctx);
2255- }
2256- }
2257 }2383 }
2258 fctx.recon_spare.with(|c| *c.borrow_mut() = ops);2384 fctx.recon_spare.with(|c| *c.borrow_mut() = ops);
2259 }2385 }
2260 2386
2387+/// Performs one recorded write: the body [`flush_recon`] replays, and the
2388+/// body [`push_op`] runs immediately when reconstruction is inline.
2389+fn exec_op(
2390+ op: ReconOp,
2391+ y: &mut PlaneBuf<'static>,
2392+ u: &mut PlaneBuf<'static>,
2393+ v: &mut PlaneBuf<'static>,
2394+ fctx: &crate::decode::FrameCtx,
2395+) {
2396+ match op {
2397+ ReconOp::Intra {
2398+ plane, x, y: oy, bw, bh, rect, mode, angle_delta, reach, residual, cfl,
2399+ filter_intra, smooth_neighbor, pred,
2400+ } => exec_intra(
2401+ y, u, v, plane, x, oy, bw, bh, rect, mode, angle_delta, reach, &residual, cfl,
2402+ filter_intra, smooth_neighbor, pred, fctx,
2403+ ),
2404+ ReconOp::Mc { plane, x, y: oy, stride, w, h, prediction, residual } => {
2405+ exec_mc(y, u, v, plane, x, oy, stride, w, h, &prediction, &residual, fctx);
2406+ }
2407+ }
2408+}
2409+
2410+/// [`ReconOp::Intra`] performed. Its arguments are borrowed, so the inline
2411+/// path ([`push_op`]'s registered planes) reaches it without ever building
2412+/// the record -- which is what keeps one reconstruction thread at the cost of
2413+/// the pre-lane-wave1 decoder.
2414+#[allow(clippy::too_many_arguments)]
2415+fn exec_intra(
2416+ y: &mut PlaneBuf<'static>,
2417+ u: &mut PlaneBuf<'static>,
2418+ v: &mut PlaneBuf<'static>,
2419+ plane: usize,
2420+ x: usize,
2421+ oy: usize,
2422+ bw: usize,
2423+ bh: usize,
2424+ rect: bool,
2425+ mode: usize,
2426+ angle_delta: i32,
2427+ reach: Reach,
2428+ residual: &[i32],
2429+ cfl: Option<(i32, CflSrc)>,
2430+ filter_intra: Option<usize>,
2431+ smooth_neighbor: bool,
2432+ pred: Option<Vec<u16>>,
2433+ fctx: &crate::decode::FrameCtx,
2434+) {
2435+ // The CfL AC signal is read HERE, off the luma that has already been
2436+ // written for this block -- at parse time it would have been the previous
2437+ // frame's samples.
2438+ let ac = cfl.map(|(alpha, src)| {
2439+ let sig = if src.rect {
2440+ cfl_ac_q3_rect(&*y, src.px, src.py, src.bw, src.bh)
2441+ } else {
2442+ cfl_ac_q3(&*y, src.px, src.py, src.bw)
2443+ };
2444+ (alpha, sig)
2445+ });
2446+ let cfl = ac.as_ref().map(|(a, sig)| (*a, sig.as_slice()));
2447+ let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2448+ if rect {
2449+ target.reconstruct_rect(
2450+ x, oy, bw, bh, mode, angle_delta, reach, residual, cfl, filter_intra,
2451+ smooth_neighbor, pred, fctx,
2452+ );
2453+ } else {
2454+ target.reconstruct(
2455+ x, oy, bw, mode, angle_delta, reach, residual, cfl, filter_intra,
2456+ smooth_neighbor, pred, fctx,
2457+ );
2458+ }
2459+}
2460+
2461+/// [`ReconOp::Mc`] performed -- see [`exec_intra`].
2462+#[allow(clippy::too_many_arguments)]
2463+fn exec_mc(
2464+ y: &mut PlaneBuf<'static>,
2465+ u: &mut PlaneBuf<'static>,
2466+ v: &mut PlaneBuf<'static>,
2467+ plane: usize,
2468+ x: usize,
2469+ oy: usize,
2470+ stride: usize,
2471+ w: usize,
2472+ h: usize,
2473+ prediction: &[u16],
2474+ residual: &[i32],
2475+ fctx: &crate::decode::FrameCtx,
2476+) {
2477+ let target: &mut PlaneBuf<'static> = match plane { 0 => &mut *y, 1 => &mut *u, _ => &mut *v };
2478+ target.reconstruct_mc_rect(x, oy, stride, w, h, prediction, residual, fctx);
2479+}
2480+
2261 thread_local! {2481 thread_local! {
2262 /// The current frame's `mi` grid, kept only while a frame header set2482 /// The current frame's `mi` grid, kept only while a frame header set
2263 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary2483 /// `allow_intrabc` -- an intrabc block's DV predictor is the ordinary
@@ -18631,6 +18851,9 @@ pub(crate) fn decode_key_frame_tile_with_cdfs(
18631 // its one block covers all four 64x64 quadrants, so the remaining three18851 // its one block covers all four 64x64 quadrants, so the remaining three
18632 // visits of this superblock code nothing at all.18852 // visits of this superblock code nothing at all.
18633 let mut sb128_none = false;18853 let mut sb128_none = false;
18854+ // lane-wave1 step (ii): at one reconstruction thread the recorded writes
18855+ // are performed at their push sites (nothing reaches the queue below).
18856+ let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v);
18634 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {18857 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
18635 // lane-wave1 step (i): the previous superblock's recorded writes.18858 // lane-wave1 step (i): the previous superblock's recorded writes.
18636 flush_recon(fctx, &mut y, &mut u, &mut v);18859 flush_recon(fctx, &mut y, &mut u, &mut v);
@@ -30083,6 +30306,9 @@ pub(crate) fn decode_inter_frame_tile_with_cdfs(
30083 // three items of this superblock carry no syntax at all (same skip the30306 // three items of this superblock carry no syntax at all (same skip the
30084 // key-frame tile loop runs).30307 // key-frame tile loop runs).
30085 let mut sb128_none = false;30308 let mut sb128_none = false;
30309+ // lane-wave1 step (ii): at one reconstruction thread the recorded writes
30310+ // are performed at their push sites (nothing reaches the queue below).
30311+ let _recon_inline = ReconInline::install(fctx, &mut y, &mut u, &mut v);
30086 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {30312 for (sb_r, sb_c, row_start, sb_start) in sb_visit_order(sb_r0, sb_r1, sb_c0, sb_c1, sb128) {
30087 // lane-wave1 step (i): the previous superblock's recorded writes.30313 // lane-wave1 step (i): the previous superblock's recorded writes.
30088 flush_recon(fctx, &mut y, &mut u, &mut v);30314 flush_recon(fctx, &mut y, &mut u, &mut v);
crates/ec-av1/src/par.rsmodified+28 -0
@@ -133,3 +133,31 @@ where
133 }133 }
134 }134 }
135 }135 }
136+
137+/// `EC_AV1_RECON_THREADS`, the number of worker threads a tile's
138+/// reconstruction (lane-wave1) is spread across, in superblock-row wavefront
139+/// order (default 1 = reconstruct inline at the parse site, i.e. exactly the
140+/// pre-wavefront decoder). Read once per process, same shape as
141+/// [`filter_threads`].
142+static RECON_THREADS: std::sync::atomic::AtomicUsize = std::sync::atomic::AtomicUsize::new(0);
143+
144+pub(crate) fn recon_threads() -> usize {
145+ match RECON_THREADS.load(std::sync::atomic::Ordering::Relaxed) {
146+ 0 => {
147+ let n = crate::envflags::var("EC_AV1_RECON_THREADS")
148+ .ok()
149+ .and_then(|v| v.trim().parse::<usize>().ok())
150+ .unwrap_or(1)
151+ .clamp(1, 64);
152+ RECON_THREADS.store(n, std::sync::atomic::Ordering::Relaxed);
153+ n
154+ }
155+ n => n,
156+ }
157+}
158+
159+/// Test-only override of [`recon_threads`] -- see [`set_filter_threads`].
160+#[cfg(test)]
161+pub(crate) fn set_recon_threads(n: usize) {
162+ RECON_THREADS.store(n.clamp(1, 64), std::sync::atomic::Ordering::Relaxed);
163+}