CPU profile (WPR) on a 9800X3D: CPU saturated, busiest game thread spins in Sleep(0), list threads lose ~27% to locks #2707

Open
opened 2026-11-30 09:16:34 +00:00 by Yizzii · 2 comments
Yizzii commented 2026-11-30 09:16:34 +00:00 (Migrated from github.com)
Contributor

Imported from ubiquitarianism/leonida. Originally posted by Yizzii on 2026-11-30T09:16:34Z.


CPU profile of a standing run with Windows' own profiler: the CPU is saturated, the busiest title thread mostly waits, and the list threads spend over a quarter of their time taking and releasing locks

Follow-up to #2614, with a whole-process CPU profile taken from outside the game.

Setup

  • RTX 5070 Ti, Ryzen 7 9800X3D (8 cores / 16 threads), 32 GB, Windows
  • mandy bbd45f5cc, built with build-nvidia.ps1, started through play-nvidia.ps1 -Log -NoFrameGen with its defaults (LEONIDA_GAME_ACTIONS=0)
  • Standing still at the same spot in every run, with the idle camera cutting between angles. Frame generation off. In the lighter view it runs at about 31-33 fps, in the heavier one at about 23-27 (see the settings table below).
  • Profiler: Windows Performance Recorder (wpr -start CPU, 20 s, about 90 s into the world), converted with tracerpt to CSV. Samples are about 0.57 ms apart. leonida addresses are symbolized with this build's pdb. Title addresses are image-relative at the preferred base 0x140000000, so they match a disassembly of the executable.

It's one 20 s recording, so treat the percentages as approximate. It started about 90 s into the world, just as the camera cut to the heavier view. According to the frame lines, the first half or so was the heavier view (about 11,200 draws a frame, 23-24 fps) and the rest the lighter one (about 5,800-5,900 draws, 28-29 fps). So the profile leans towards the heavier view.

1. The CPU is saturated

Over the 20 s, as logical CPUs busy out of 16:

Process CPUs busy
leonida_sm.exe 13.65
everything else about 2.2 (Discord 1.1)
idle 0.14

Inside leonida_sm.exe, the title's own 49 threads use about 5.1 CPUs and the rest of the process (leonida's threads, plus the driver's and DirectStorage's) about 8.5, the six list threads alone 5.3. So nothing on this machine has a free core. The submitting thread, the list threads and the title's threads all compete for SMT siblings. That might explain why more helper threads didn't help here (results below).

2. The busiest title thread is mostly waiting (Sleep(0) spin)

Busiest threads of the process, in ms of CPU per second:

Thread ms/s
leonida-list-0..5 (6 threads) 868-918 each, about 5.3 CPUs together
leonida-submit 830
busiest title thread (the wait loop below) 579
title thread (audio, see 4) 414
other title threads 380, 355, 318, 293, 264, 227, ...
leonida-relay 216

All the title's threads start at the image's +0x2215ea0. That 579 ms/s title thread breaks down as:

  • 58% in the kernel
  • 30% in title code, two thirds of it (20.4% of the thread) in one function, 0x144fb0ad0
  • 9% in ntdll

0x144fb0ad0 is a wait loop. It's called through 0x144fb0a90, with 0x142474740, 0x1424846d0, 0x140c9e5e0, 0x140120790 and 0x14011fd60 above it on the stack:

  • It gets a pointer to a 64-bit value through a virtual call ([vtable+0x60]) and waits until the value reaches a target (the sign of value - target at bit 55). It looks like a fence's completed value, but I haven't confirmed what it is.
  • Each pass is monitorx / mwaitx, then a call to 0x144fb0e90, which is Sleep(0) (a jump through the import at 0x146793b98, the title's Sleep). If the two wait instructions fault on this CPU, LEONIDA_PATCH_WAITS turns them into a no-op and pause. Otherwise they run natively. I didn't check which, since the log doesn't say.
  • Another path through the same function (0x144fb0d7c onwards) calls 0x14092eca0, which is Sleep(1) through the same import.

On the console Sleep(0) presumably costs little. On Windows every call is a trip into the kernel, which would explain the 58% kernel time. So this thread mostly waits for whatever produces that value, and the waiting costs most of a core on a CPU with none to spare.

Possible fix: recognise this loop and wait on the value instead, with a short pause spin and then WaitOnAddress or an event. SwitchToThread wouldn't help, since it's also a kernel call. That should give most of a core back to the threads doing real work. Untested; it's only what the profile suggests.

3. The list threads: over a quarter of their time in locks

Each leonida-list-* thread is about 90% busy, and 70% of their samples are inside leonida_sm.exe. Of those, by innermost (inlined) function:

Function Share
std::sys::sync::mutex::futex::Mutex::lock 10.5%
std::sys::sync::mutex::futex::Mutex::unlock 10.2%
std::sys::sync::rwlock::futex::RwLock::read 8.7%
RwLock::read_unlock 5.7%
read_contended 3.2%
atomic_add 3.9%
alloc::sync clone (Arc) 3.1%

That's about 38% of their time in leonida spent in lock and unlock alone, about 27% of their time overall. Most of it is the lock operations' own cost. Where a lock was actually contended (read_contended and lock_contended), it's about 5.6% by outermost function in the tables below. By outermost function, the biggest are:

Function Share
leonida_gpu::descriptor::view_at 16.7%
draw::State::tables 7.1%
resource::hosted 4.2%
descriptor::host::placed_texture 3.5%
defer_refresh 3.2%
deferred_steps 3.0%
draw::State::bind 2.8%
descriptor::host::table_r9g9b9e5_views 2.7%
shadow::lookup 2.5%

So the six list threads spend a lot of their time taking and releasing the same few locks around descriptor and resource lookups. With six threads on them, the locks' cache lines probably move between cores a lot. Fewer lock round trips per draw (or per-thread caches for view_at) look like the biggest CPU saving in the profile. Outside leonida, their samples are mostly in nvwgf2umx.dll, D3D12.dll and D3D12Core.dll, plus some kernel time.

4. The audio thread decodes Opus in software

One title thread (414 ms/s) spends about 42% of its samples in leonida_sm.exe, most of it in leonida_hle::modules::apu::XApuEnqueueCommand → Opus decoding (opus_pure::celt::*, opus_pure::silk::*, about 36% of its stacks) and dsp::XDspSubmitCommand / convolve::Fft::run. That's about 0.17 of a CPU. It's not on the frame's path, but it adds to the saturation.

5. The submitting thread

830 ms/s. Of its samples, about 28% are in the kernel and about 16% in nvwgf2umx.dll. Of its samples inside leonida, the top ones are leonida_safe_copy_at 10%, Host::submit 7%, Instant::now 6%, host::copy_mapped 5%, then allocations (Vec::from_iter, the allocator's alloc and realloc, reserve_rehash, about 14% together), Shadow::nothing_new, blocked_by and stale_under_flights.

Some of what the tables show looks like bookkeeping rather than work. These are small, but none of them are free on a full CPU. Percentages are of each thread's samples inside leonida:

  • Instant::now (6.0%) plus mul_div_u64 (3.9% innermost) on the submitting thread. These are time queries, presumably for the per-frame statistics.
  • copystat::Counting, the counting global allocator: in alloc, 4.1% of the submitting thread's samples in leonida and 1.6% of the list threads', plus realloc.
  • copystat::recorded: 1.8% of the list threads.
  • SipHash (core::hash::sip::Hasher::write): 1.3% of the list threads.

Settings tried, and the new build vs the previous one (same spot, 4 min each)

The idle camera cuts between a lighter view (under 6,500 draws a frame) and heavier ones (over 8,000), and how much time each run spends in each differs. So besides the overall median, here are the medians for each view on its own. Frame lines between 6,500 and 8,000 draws (13 in the old build's second baseline, 2 in the new build's first, none in the others) only count in the overall median:

Build / run Median fps, all Lighter view (< 6,500 draws) Heavier view (> 8,000 draws)
9e3218f0e baseline 32.9 33.0 29.2
9e3218f0e baseline (2nd) 33.3 34.0 29.5
bbd45f5cc baseline 31.2 31.8 26.6
bbd45f5cc baseline (2nd) 32.4 32.8 26.1
bbd45f5cc + LEONIDA_AHEAD_SPLIT=1 28.3 32.9 26.3
bbd45f5cc + LEONIDA_AHEAD_SPLIT=1 + LEONIDA_WIDE_HALF=1 32.3 32.7 25.7
bbd45f5cc + LEONIDA_WIDE_HALF=1 27.9 32.3 25.9
bbd45f5cc + LEONIDA_WIDE_THREADS=12 31.5 32.0 25.3
  • None of the settings did anything measurable. In each view they're within about ±1 fps of the two bbd45f5cc baselines. Their lower overall medians (28.3, 27.9) only come from spending more of the run in the heavier view.
  • bbd45f5cc is slower than 9e3218f0e here, mostly in the heavier view: about 26 fps against about 29, in all six runs on the new build. In the first baseline of each build, with nearly the same draws in the heavier view (a mean of 9,775 against 9,758 a frame), the mean is 26.5 fps against 29.0. The lighter view is down about 1 fps. Per frame, the new build cuts refreshes (7.1 to 5.9 ms) and copies (10.8 to 9.5 ms), but copying back grew (7.4 to 9.6 ms).
  • Caveat: the old and new builds ran on different days, with possibly different programs in the background. Within each build, though, the runs agree.

Side note: LEONIDA_PROFILE on title threads crashed the title

LEONIDA_PROFILE=200,260,2,<file> with LEONIDA_PROFILE_ONLY matching the title's threads (leonida-image-...dll+0x2215ea) crashed the title about 2 s after the profile begins: unhandled exception 0xc0000005 at ntdll.dll+0x1ff2a (read 0x3: nothing mapped there). It happened once. The same profiler on leonida's own threads (LEONIDA_PROFILE_ONLY=leonida-submit) worked fine on the previous build. Probably the in-process suspend-and-unwind hitting a title thread at a bad moment. An external profiler (WPR/ETW) works fine for title threads.

Tables

Symbolized with this build's pdb (llvm-symbolizer). Percentages are of the samples in the summary line. Title addresses are function starts taken from the image's unwind table.

leonida-list-0..5 together (132,674 samples in leonida_sm.exe)

By function (outermost; inlined code counted in the function it was inlined into):

% function
16.7 leonida_gpu::descriptor::view_at
7.1 leonida_gpu::draw::State::tables
4.3 thread_local with (for leonida_gpu::descriptor::host::HostHeap)
4.2 leonida_gpu::resource::hosted
4.2 <std::sys::sync::rwlock::futex::RwLock>::read_contended
3.5 leonida_gpu::descriptor::host::placed_texture
3.2 <leonida_gpu::host::HostList>::defer_refresh
3.0 <leonida_gpu::host::HostList>::deferred_steps
2.8 leonida_gpu::draw::State::bind
2.7 leonida_gpu::descriptor::host::table_r9g9b9e5_views
2.5 leonida_gpu::shadow::lookup
2.1 thread_local with (for leonida_gpu::shadow::found)
1.8 leonida_gpu::copystat::recorded
1.8 <alloc::collections::btree::node::NodeRef>::search_tree::
1.7 <leonida_gpu::host::HostList>::first_use
1.6 <leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::alloc
1.6 leonida_gpu::resource::want_level
1.5 <hashbrown::map::HashMap>::insert
1.5 leonida_gpu::draw::impl$13::tables::closure$3
1.4 <std::sys::sync::mutex::futex::Mutex>::lock_contended
1.3 <core::hash::sip::Hasher as core::hash::Hasher>::write
1.2 <leonida_gpu::host::HostList>::transition
1.2 leonida_gpu::descriptor::host::buffer_srv
1.2 leonida_gpu::list::with_state::
1.1 <hashbrown::raw::RawTable>::reserve_rehash::

By innermost (inlined) function:

% function
10.5 std::sys::sync::mutex::futex::Mutex::lock
10.2 std::sys::sync::mutex::futex::Mutex::unlock
8.7 std::sys::sync::rwlock::futex::RwLock::read
5.7 std::sys::sync::rwlock::futex::RwLock::read_unlock
3.9 core::sync::atomic::atomic_add
3.2 <std::sys::sync::rwlock::futex::RwLock>::read_contended
3.1 alloc::sync::impl$32::clone
3.0 leonida_gpu::draw::State::tables
3.0 std::sys::sync::rwlock::futex::is_read_lockable
2.1 core::sync::atomic::Atomic::try_update
2.0 alloc::sync::impl$42::drop
1.9 core::option::Option::as_ref
leonida-submit (12,327 samples in leonida_sm.exe)

By function (outermost; inlined code counted in the function it was inlined into):

% function
10.2 leonida_safe_copy_at
6.9 <leonida_gpu::host::Host>::submit
6.0 <std::time::Instant>::now
5.3 <alloc::vec::Vec as alloc::vec::spec_from_iter_nested::SpecFromIterNested>::from_iter
4.8 leonida_gpu::host::copy_mapped
4.1 <leonida_gpu::shadow::Shadow>::nothing_new
4.1 <leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::alloc
3.8 leonida_gpu::host::blocked_by
2.5 leonida_gpu::host::stale_under_flights
2.2 <hashbrown::raw::RawTable>::reserve_rehash::
2.1 <leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::realloc
2.0 leonida_gpu::host::declared_writes
1.9 <leonida_gpu::shadow::Shadow>::merge_under_writes
1.8 leonida_gpu::shadow::word_runs_avx2
1.7 <alloc::collections::btree::node::NodeRef>::find_leaf_edges_spanning_range::
1.7 leonida_gpu::shadow::send_copied
1.5 core::slice::sort::stable::drift::sort::
1.3 leonida_gpu::watch::Shard::note
1.1 mi_malloc_aligned
1.1 leonida_gpu::watch::journal
1.1 leonida_gpu::host::send::take::closure$7
1.0 <leonida_gpu::shadow::Shadow>::writing
1.0 leonida_gpu::host::send::take
0.9 <alloc::vec::Vec>::extend_desugared::
0.9 leonida_gpu::host::joinable::

By innermost (inlined) function:

% function
10.2 leonida_safe_copy_at
9.3 core::sync::atomic::atomic_add
4.8 core::sync::atomic::Atomic::try_update
3.9 std::sys::helpers::mul_div_u64
3.2 std::sys::sync::mutex::futex::Mutex::unlock
2.7 core::sync::atomic::atomic_sub
2.5 std::sys::sync::mutex::futex::Mutex::lock
2.3 alloc::sync::impl$42::drop
1.5 leonida_gpu::host::declared_writes
1.4 leonida_gpu::copystat::big
1.4 core::time::Duration::from_nanos
1.4 leonida_gpu::shadow::word_runs_avx2_in
The title's audio thread, its time in leonida_sm.exe (6,090 samples in leonida_sm.exe)

By function (outermost; inlined code counted in the function it was inlined into):

% function
12.2 opus_pure::celt::bands::quant_partition
12.0 leonida_hle::modules::dsp::XDspSubmitCommand
10.0 <opus_pure::celt::CeltDecoder>::decode_impl_from_rc
6.4 opus_pure::silk::decode_core::silk_decode_core
6.3 leonida_hle::modules::dsp::convolve::Fft::run
6.1 opus_pure::celt::kiss_fft::opus_fft_impl
4.7 opus_pure::celt::pvq::exp_rotation1_scalar
4.0 opus_pure::silk::decode_pulses::silk_decode_pulses
4.0 opus_pure::silk::resampler::silk_resampler_private_up2_hq
4.0 opus_pure::celt::mdct::MdctLookup::backward
3.9 <opus_pure::decoder::OpusDecoder>::decode_native
3.7 opus_pure::silk::decode_pulses::decode_split
3.6 opus_pure::silk::resampler::SilkResampler::iir_fir_block
2.5 opus_pure::celt::rate::clt_compute_allocation
2.5 opus_pure::celt::bands::quant_all_bands

By innermost (inlined) function:

% function
11.5 leonida_hle::modules::dsp::convolve::Convolver::process
5.3 leonida_hle::modules::dsp::convolve::Fft::run
4.7 opus_pure::celt::pvq::exp_rotation1_scalar
4.3 opus_pure::celt::deemphasis
3.9 opus_pure::silk::macros::silk_smulwb
2.9 opus_pure::celt::pvq::cwrsi
2.7 opus_pure::range_coder::RangeCoder::decode_icdf
2.3 opus_pure::silk::resampler::silk_resampler_private_up2_hq
The busiest title thread (the wait loop) (20,418 samples, 579 ms of CPU a second)

By module:

% module
58.2 kernel
29.8 title code
9.1 ntdll.dll
2.0 leonida_sm.exe
0.4 KernelBase.dll
0.2 vcruntime140.dll
0.1 ucrtbase.dll
0.1 ?

Title functions (start address from the image's unwind table, base 0x140000000), % of all the samples above:

% function
20.4 0x144fb0ad0
1.3 0x144dbf3c0
1.0 0x144dbda30
0.8 0x144dbe690
0.7 0x14010a0c0
0.6 0x144e3b090
0.5 0x144e8a9f0
0.5 0x144da9ec0
0.3 0x144f6a7c0
0.2 0x144da9b00
The other 47 title threads together (not the audio thread) (145,608 samples, 4129 ms of CPU a second)

By module:

% module
74.5 title code
14.4 kernel
7.4 leonida_sm.exe
1.3 vcruntime140.dll
0.8 ntdll.dll
0.7 ?
0.5 ucrtbase.dll
0.1 KernelBase.dll

Title functions (start address from the image's unwind table, base 0x140000000), % of all the samples above:

% function
1.2 0x143261fd0
1.1 0x140096f50
1.1 0x1435a3b80
0.9 0x14258b150
0.8 0x140031e30
0.7 0x140004b40
0.6 0x144d9ed60
0.6 0x144eea9a0
0.5 0x144d9d9f0
0.5 0x144e4af00
0.5 0x144d9efd0
0.5 0x14008eee0
0.4 0x144e53ef0
0.4 0x144f2ab60
0.4 0x145070530
0.4 0x1401d7580
0.4 0x145383290
0.4 0x144f738f0
0.3 0x140013900
0.3 0x144ebd630
0.3 0x14221c1f0
0.3 0x142628250
0.3 0x144f42210
0.3 0x14227a320
0.3 0x140110ed0
<!-- greyfinch-sync:ubiquitarianism/leonida:issue:6692883842 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2707). Originally posted by [Yizzii](https://github.com/Yizzii) on 2026-11-30T09:16:34Z. --- ## CPU profile of a standing run with Windows' own profiler: the CPU is saturated, the busiest title thread mostly waits, and the list threads spend over a quarter of their time taking and releasing locks Follow-up to #2614, with a whole-process CPU profile taken from outside the game. ### Setup - RTX 5070 Ti, Ryzen 7 9800X3D (8 cores / 16 threads), 32 GB, Windows - mandy `bbd45f5cc`, built with `build-nvidia.ps1`, started through `play-nvidia.ps1 -Log -NoFrameGen` with its defaults (`LEONIDA_GAME_ACTIONS=0`) - Standing still at the same spot in every run, with the idle camera cutting between angles. Frame generation off. In the lighter view it runs at about 31-33 fps, in the heavier one at about 23-27 (see the settings table below). - Profiler: Windows Performance Recorder (`wpr -start CPU`, 20 s, about 90 s into the world), converted with `tracerpt` to CSV. Samples are about 0.57 ms apart. leonida addresses are symbolized with this build's pdb. Title addresses are image-relative at the preferred base `0x140000000`, so they match a disassembly of the executable. It's one 20 s recording, so treat the percentages as approximate. It started about 90 s into the world, just as the camera cut to the heavier view. According to the frame lines, the first half or so was the heavier view (about 11,200 draws a frame, 23-24 fps) and the rest the lighter one (about 5,800-5,900 draws, 28-29 fps). So the profile leans towards the heavier view. ### 1. The CPU is saturated Over the 20 s, as logical CPUs busy out of 16: | Process | CPUs busy | |---|---| | leonida_sm.exe | 13.65 | | everything else | about 2.2 (Discord 1.1) | | idle | 0.14 | Inside leonida_sm.exe, the title's own 49 threads use about 5.1 CPUs and the rest of the process (leonida's threads, plus the driver's and DirectStorage's) about 8.5, the six list threads alone 5.3. So nothing on this machine has a free core. The submitting thread, the list threads and the title's threads all compete for SMT siblings. That might explain why more helper threads didn't help here (results below). ### 2. The busiest title thread is mostly waiting (Sleep(0) spin) Busiest threads of the process, in ms of CPU per second: | Thread | ms/s | |---|---| | leonida-list-0..5 (6 threads) | 868-918 each, about 5.3 CPUs together | | leonida-submit | 830 | | busiest title thread (the wait loop below) | **579** | | title thread (audio, see 4) | 414 | | other title threads | 380, 355, 318, 293, 264, 227, ... | | leonida-relay | 216 | All the title's threads start at the image's `+0x2215ea0`. That 579 ms/s title thread breaks down as: - **58% in the kernel** - 30% in title code, two thirds of it (20.4% of the thread) in one function, `0x144fb0ad0` - 9% in ntdll `0x144fb0ad0` is a wait loop. It's called through `0x144fb0a90`, with `0x142474740`, `0x1424846d0`, `0x140c9e5e0`, `0x140120790` and `0x14011fd60` above it on the stack: - It gets a pointer to a 64-bit value through a virtual call (`[vtable+0x60]`) and waits until the value reaches a target (the sign of `value - target` at bit 55). It looks like a fence's completed value, but I haven't confirmed what it is. - Each pass is `monitorx` / `mwaitx`, then a call to `0x144fb0e90`, which is **`Sleep(0)`** (a jump through the import at `0x146793b98`, the title's `Sleep`). If the two wait instructions fault on this CPU, `LEONIDA_PATCH_WAITS` turns them into a no-op and `pause`. Otherwise they run natively. I didn't check which, since the log doesn't say. - Another path through the same function (`0x144fb0d7c` onwards) calls `0x14092eca0`, which is **`Sleep(1)`** through the same import. On the console `Sleep(0)` presumably costs little. On Windows every call is a trip into the kernel, which would explain the 58% kernel time. So this thread mostly waits for whatever produces that value, and the waiting costs most of a core on a CPU with none to spare. Possible fix: recognise this loop and wait on the value instead, with a short `pause` spin and then `WaitOnAddress` or an event. `SwitchToThread` wouldn't help, since it's also a kernel call. That should give most of a core back to the threads doing real work. Untested; it's only what the profile suggests. ### 3. The list threads: over a quarter of their time in locks Each `leonida-list-*` thread is about 90% busy, and 70% of their samples are inside leonida_sm.exe. Of those, by innermost (inlined) function: | Function | Share | |---|---| | `std::sys::sync::mutex::futex::Mutex::lock` | 10.5% | | `std::sys::sync::mutex::futex::Mutex::unlock` | 10.2% | | `std::sys::sync::rwlock::futex::RwLock::read` | 8.7% | | `RwLock::read_unlock` | 5.7% | | `read_contended` | 3.2% | | `atomic_add` | 3.9% | | `alloc::sync` clone (`Arc`) | 3.1% | That's about 38% of their time in leonida spent in lock and unlock alone, about 27% of their time overall. Most of it is the lock operations' own cost. Where a lock was actually contended (`read_contended` and `lock_contended`), it's about 5.6% by outermost function in the tables below. By outermost function, the biggest are: | Function | Share | |---|---| | `leonida_gpu::descriptor::view_at` | 16.7% | | `draw::State::tables` | 7.1% | | `resource::hosted` | 4.2% | | `descriptor::host::placed_texture` | 3.5% | | `defer_refresh` | 3.2% | | `deferred_steps` | 3.0% | | `draw::State::bind` | 2.8% | | `descriptor::host::table_r9g9b9e5_views` | 2.7% | | `shadow::lookup` | 2.5% | So the six list threads spend a lot of their time taking and releasing the same few locks around descriptor and resource lookups. With six threads on them, the locks' cache lines probably move between cores a lot. Fewer lock round trips per draw (or per-thread caches for `view_at`) look like the biggest CPU saving in the profile. Outside leonida, their samples are mostly in nvwgf2umx.dll, D3D12.dll and D3D12Core.dll, plus some kernel time. ### 4. The audio thread decodes Opus in software One title thread (414 ms/s) spends about 42% of its samples in leonida_sm.exe, most of it in `leonida_hle::modules::apu::XApuEnqueueCommand` → Opus decoding (`opus_pure::celt::*`, `opus_pure::silk::*`, about 36% of its stacks) and `dsp::XDspSubmitCommand` / `convolve::Fft::run`. That's about 0.17 of a CPU. It's not on the frame's path, but it adds to the saturation. ### 5. The submitting thread 830 ms/s. Of its samples, about 28% are in the kernel and about 16% in nvwgf2umx.dll. Of its samples inside leonida, the top ones are `leonida_safe_copy_at` 10%, `Host::submit` 7%, `Instant::now` 6%, `host::copy_mapped` 5%, then allocations (`Vec::from_iter`, the allocator's `alloc` and `realloc`, `reserve_rehash`, about 14% together), `Shadow::nothing_new`, `blocked_by` and `stale_under_flights`. Some of what the tables show looks like bookkeeping rather than work. These are small, but none of them are free on a full CPU. Percentages are of each thread's samples inside leonida: - `Instant::now` (6.0%) plus `mul_div_u64` (3.9% innermost) on the submitting thread. These are time queries, presumably for the per-frame statistics. - `copystat::Counting`, the counting global allocator: in `alloc`, 4.1% of the submitting thread's samples in leonida and 1.6% of the list threads', plus `realloc`. - `copystat::recorded`: 1.8% of the list threads. - SipHash (`core::hash::sip::Hasher::write`): 1.3% of the list threads. ### Settings tried, and the new build vs the previous one (same spot, 4 min each) The idle camera cuts between a lighter view (under 6,500 draws a frame) and heavier ones (over 8,000), and how much time each run spends in each differs. So besides the overall median, here are the medians for each view on its own. Frame lines between 6,500 and 8,000 draws (13 in the old build's second baseline, 2 in the new build's first, none in the others) only count in the overall median: | Build / run | Median fps, all | Lighter view (< 6,500 draws) | Heavier view (> 8,000 draws) | |---|---|---|---| | `9e3218f0e` baseline | 32.9 | 33.0 | 29.2 | | `9e3218f0e` baseline (2nd) | 33.3 | 34.0 | 29.5 | | `bbd45f5cc` baseline | 31.2 | 31.8 | 26.6 | | `bbd45f5cc` baseline (2nd) | 32.4 | 32.8 | 26.1 | | `bbd45f5cc` + `LEONIDA_AHEAD_SPLIT=1` | 28.3 | 32.9 | 26.3 | | `bbd45f5cc` + `LEONIDA_AHEAD_SPLIT=1` + `LEONIDA_WIDE_HALF=1` | 32.3 | 32.7 | 25.7 | | `bbd45f5cc` + `LEONIDA_WIDE_HALF=1` | 27.9 | 32.3 | 25.9 | | `bbd45f5cc` + `LEONIDA_WIDE_THREADS=12` | 31.5 | 32.0 | 25.3 | - **None of the settings did anything measurable.** In each view they're within about ±1 fps of the two `bbd45f5cc` baselines. Their lower overall medians (28.3, 27.9) only come from spending more of the run in the heavier view. - **`bbd45f5cc` is slower than `9e3218f0e` here, mostly in the heavier view:** about 26 fps against about 29, in all six runs on the new build. In the first baseline of each build, with nearly the same draws in the heavier view (a mean of 9,775 against 9,758 a frame), the mean is 26.5 fps against 29.0. The lighter view is down about 1 fps. Per frame, the new build cuts refreshes (7.1 to 5.9 ms) and copies (10.8 to 9.5 ms), but copying back grew (7.4 to 9.6 ms). - **Caveat:** the old and new builds ran on different days, with possibly different programs in the background. Within each build, though, the runs agree. ### Side note: LEONIDA_PROFILE on title threads crashed the title `LEONIDA_PROFILE=200,260,2,<file>` with `LEONIDA_PROFILE_ONLY` matching the title's threads (`leonida-image-...dll+0x2215ea`) crashed the title about 2 s after `the profile begins`: `unhandled exception 0xc0000005 at ntdll.dll+0x1ff2a (read 0x3: nothing mapped there)`. It happened once. The same profiler on leonida's own threads (`LEONIDA_PROFILE_ONLY=leonida-submit`) worked fine on the previous build. Probably the in-process suspend-and-unwind hitting a title thread at a bad moment. An external profiler (WPR/ETW) works fine for title threads. ### Tables Symbolized with this build's pdb (`llvm-symbolizer`). Percentages are of the samples in the summary line. Title addresses are function starts taken from the image's unwind table. <details><summary>leonida-list-0..5 together (132,674 samples in leonida_sm.exe)</summary> By function (outermost; inlined code counted in the function it was inlined into): | % | function | |---|---| | 16.7 | `leonida_gpu::descriptor::view_at` | | 7.1 | `leonida_gpu::draw::State::tables` | | 4.3 | `thread_local with (for leonida_gpu::descriptor::host::HostHeap)` | | 4.2 | `leonida_gpu::resource::hosted` | | 4.2 | `<std::sys::sync::rwlock::futex::RwLock>::read_contended` | | 3.5 | `leonida_gpu::descriptor::host::placed_texture` | | 3.2 | `<leonida_gpu::host::HostList>::defer_refresh` | | 3.0 | `<leonida_gpu::host::HostList>::deferred_steps` | | 2.8 | `leonida_gpu::draw::State::bind` | | 2.7 | `leonida_gpu::descriptor::host::table_r9g9b9e5_views` | | 2.5 | `leonida_gpu::shadow::lookup` | | 2.1 | `thread_local with (for leonida_gpu::shadow::found)` | | 1.8 | `leonida_gpu::copystat::recorded` | | 1.8 | `<alloc::collections::btree::node::NodeRef>::search_tree::` | | 1.7 | `<leonida_gpu::host::HostList>::first_use` | | 1.6 | `<leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::alloc` | | 1.6 | `leonida_gpu::resource::want_level` | | 1.5 | `<hashbrown::map::HashMap>::insert` | | 1.5 | `leonida_gpu::draw::impl$13::tables::closure$3` | | 1.4 | `<std::sys::sync::mutex::futex::Mutex>::lock_contended` | | 1.3 | `<core::hash::sip::Hasher as core::hash::Hasher>::write` | | 1.2 | `<leonida_gpu::host::HostList>::transition` | | 1.2 | `leonida_gpu::descriptor::host::buffer_srv` | | 1.2 | `leonida_gpu::list::with_state::` | | 1.1 | `<hashbrown::raw::RawTable>::reserve_rehash::` | By innermost (inlined) function: | % | function | |---|---| | 10.5 | `std::sys::sync::mutex::futex::Mutex::lock` | | 10.2 | `std::sys::sync::mutex::futex::Mutex::unlock` | | 8.7 | `std::sys::sync::rwlock::futex::RwLock::read` | | 5.7 | `std::sys::sync::rwlock::futex::RwLock::read_unlock` | | 3.9 | `core::sync::atomic::atomic_add` | | 3.2 | `<std::sys::sync::rwlock::futex::RwLock>::read_contended` | | 3.1 | `alloc::sync::impl$32::clone` | | 3.0 | `leonida_gpu::draw::State::tables` | | 3.0 | `std::sys::sync::rwlock::futex::is_read_lockable` | | 2.1 | `core::sync::atomic::Atomic::try_update` | | 2.0 | `alloc::sync::impl$42::drop` | | 1.9 | `core::option::Option::as_ref` | </details> <details><summary>leonida-submit (12,327 samples in leonida_sm.exe)</summary> By function (outermost; inlined code counted in the function it was inlined into): | % | function | |---|---| | 10.2 | `leonida_safe_copy_at` | | 6.9 | `<leonida_gpu::host::Host>::submit` | | 6.0 | `<std::time::Instant>::now` | | 5.3 | `<alloc::vec::Vec as alloc::vec::spec_from_iter_nested::SpecFromIterNested>::from_iter` | | 4.8 | `leonida_gpu::host::copy_mapped` | | 4.1 | `<leonida_gpu::shadow::Shadow>::nothing_new` | | 4.1 | `<leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::alloc` | | 3.8 | `leonida_gpu::host::blocked_by` | | 2.5 | `leonida_gpu::host::stale_under_flights` | | 2.2 | `<hashbrown::raw::RawTable>::reserve_rehash::` | | 2.1 | `<leonida_gpu::copystat::Counting as core::alloc::global::GlobalAlloc>::realloc` | | 2.0 | `leonida_gpu::host::declared_writes` | | 1.9 | `<leonida_gpu::shadow::Shadow>::merge_under_writes` | | 1.8 | `leonida_gpu::shadow::word_runs_avx2` | | 1.7 | `<alloc::collections::btree::node::NodeRef>::find_leaf_edges_spanning_range::` | | 1.7 | `leonida_gpu::shadow::send_copied` | | 1.5 | `core::slice::sort::stable::drift::sort::` | | 1.3 | `leonida_gpu::watch::Shard::note` | | 1.1 | `mi_malloc_aligned` | | 1.1 | `leonida_gpu::watch::journal` | | 1.1 | `leonida_gpu::host::send::take::closure$7` | | 1.0 | `<leonida_gpu::shadow::Shadow>::writing` | | 1.0 | `leonida_gpu::host::send::take` | | 0.9 | `<alloc::vec::Vec>::extend_desugared::` | | 0.9 | `leonida_gpu::host::joinable::` | By innermost (inlined) function: | % | function | |---|---| | 10.2 | `leonida_safe_copy_at` | | 9.3 | `core::sync::atomic::atomic_add` | | 4.8 | `core::sync::atomic::Atomic::try_update` | | 3.9 | `std::sys::helpers::mul_div_u64` | | 3.2 | `std::sys::sync::mutex::futex::Mutex::unlock` | | 2.7 | `core::sync::atomic::atomic_sub` | | 2.5 | `std::sys::sync::mutex::futex::Mutex::lock` | | 2.3 | `alloc::sync::impl$42::drop` | | 1.5 | `leonida_gpu::host::declared_writes` | | 1.4 | `leonida_gpu::copystat::big` | | 1.4 | `core::time::Duration::from_nanos` | | 1.4 | `leonida_gpu::shadow::word_runs_avx2_in` | </details> <details><summary>The title's audio thread, its time in leonida_sm.exe (6,090 samples in leonida_sm.exe)</summary> By function (outermost; inlined code counted in the function it was inlined into): | % | function | |---|---| | 12.2 | `opus_pure::celt::bands::quant_partition` | | 12.0 | `leonida_hle::modules::dsp::XDspSubmitCommand` | | 10.0 | `<opus_pure::celt::CeltDecoder>::decode_impl_from_rc` | | 6.4 | `opus_pure::silk::decode_core::silk_decode_core` | | 6.3 | `leonida_hle::modules::dsp::convolve::Fft::run` | | 6.1 | `opus_pure::celt::kiss_fft::opus_fft_impl` | | 4.7 | `opus_pure::celt::pvq::exp_rotation1_scalar` | | 4.0 | `opus_pure::silk::decode_pulses::silk_decode_pulses` | | 4.0 | `opus_pure::silk::resampler::silk_resampler_private_up2_hq` | | 4.0 | `opus_pure::celt::mdct::MdctLookup::backward` | | 3.9 | `<opus_pure::decoder::OpusDecoder>::decode_native` | | 3.7 | `opus_pure::silk::decode_pulses::decode_split` | | 3.6 | `opus_pure::silk::resampler::SilkResampler::iir_fir_block` | | 2.5 | `opus_pure::celt::rate::clt_compute_allocation` | | 2.5 | `opus_pure::celt::bands::quant_all_bands` | By innermost (inlined) function: | % | function | |---|---| | 11.5 | `leonida_hle::modules::dsp::convolve::Convolver::process` | | 5.3 | `leonida_hle::modules::dsp::convolve::Fft::run` | | 4.7 | `opus_pure::celt::pvq::exp_rotation1_scalar` | | 4.3 | `opus_pure::celt::deemphasis` | | 3.9 | `opus_pure::silk::macros::silk_smulwb` | | 2.9 | `opus_pure::celt::pvq::cwrsi` | | 2.7 | `opus_pure::range_coder::RangeCoder::decode_icdf` | | 2.3 | `opus_pure::silk::resampler::silk_resampler_private_up2_hq` | </details> <details><summary>The busiest title thread (the wait loop) (20,418 samples, 579 ms of CPU a second)</summary> By module: | % | module | |---|---| | 58.2 | kernel | | 29.8 | title code | | 9.1 | ntdll.dll | | 2.0 | leonida_sm.exe | | 0.4 | KernelBase.dll | | 0.2 | vcruntime140.dll | | 0.1 | ucrtbase.dll | | 0.1 | ? | Title functions (start address from the image's unwind table, base `0x140000000`), % of all the samples above: | % | function | |---|---| | 20.4 | `0x144fb0ad0` | | 1.3 | `0x144dbf3c0` | | 1.0 | `0x144dbda30` | | 0.8 | `0x144dbe690` | | 0.7 | `0x14010a0c0` | | 0.6 | `0x144e3b090` | | 0.5 | `0x144e8a9f0` | | 0.5 | `0x144da9ec0` | | 0.3 | `0x144f6a7c0` | | 0.2 | `0x144da9b00` | </details> <details><summary>The other 47 title threads together (not the audio thread) (145,608 samples, 4129 ms of CPU a second)</summary> By module: | % | module | |---|---| | 74.5 | title code | | 14.4 | kernel | | 7.4 | leonida_sm.exe | | 1.3 | vcruntime140.dll | | 0.8 | ntdll.dll | | 0.7 | ? | | 0.5 | ucrtbase.dll | | 0.1 | KernelBase.dll | Title functions (start address from the image's unwind table, base `0x140000000`), % of all the samples above: | % | function | |---|---| | 1.2 | `0x143261fd0` | | 1.1 | `0x140096f50` | | 1.1 | `0x1435a3b80` | | 0.9 | `0x14258b150` | | 0.8 | `0x140031e30` | | 0.7 | `0x140004b40` | | 0.6 | `0x144d9ed60` | | 0.6 | `0x144eea9a0` | | 0.5 | `0x144d9d9f0` | | 0.5 | `0x144e4af00` | | 0.5 | `0x144d9efd0` | | 0.5 | `0x14008eee0` | | 0.4 | `0x144e53ef0` | | 0.4 | `0x144f2ab60` | | 0.4 | `0x145070530` | | 0.4 | `0x1401d7580` | | 0.4 | `0x145383290` | | 0.4 | `0x144f738f0` | | 0.3 | `0x140013900` | | 0.3 | `0x144ebd630` | | 0.3 | `0x14221c1f0` | | 0.3 | `0x142628250` | | 0.3 | `0x144f42210` | | 0.3 | `0x14227a320` | | 0.3 | `0x140110ed0` | </details>
Yizzii commented 2026-11-30 15:03:08 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ubiquitarianism/leonida. Originally posted by Yizzii on 2026-11-30T15:03:08Z.


Follow-up, same PC (RTX 5070 Ti, Ryzen 7 9800X3D), standing at the same spot, frame generation off. Sections 1 and 2 are on d367675c7, 3 and 4 on f9f3ec4c6, 5 and 6 on 20fe0c754. From section 3 on, every run has LEONIDA_VIEW_CACHE=1 (section 1).

1. LEONIDA_VIEW_CACHE helps on this CPU

LEONIDA_AB (by turns of 4 s), two runs, 186 and 228 world phases. For each switch, the mean per 8-phase round of (phases on) - (phases off), with the standard error over the rounds, for the median frame time:

Switch Run 1 (10 min, 23 rounds) Run 2 (15 min, 28 rounds)
LEONIDA_VIEW_CACHE -0.87 +-0.24 ms -1.17 +-0.21 ms (mean -1.05 +-0.23, p90 -0.98 +-0.37)
LEONIDA_CONTENT_TABLES -0.68 +-0.70 -0.54 +-0.37 (p90 -1.02 +-0.53)
LEONIDA_ALIAS_QUICK -0.23 +-0.37 (not in run 2)
LEONIDA_INDEX_HEAP_SPANS (not in run 1) -0.36 +-0.58
  • View cache: about 1 ms a frame in both runs (3.6 and 5.6 standard errors). By view, in run 2 the heavier view (more than 8,000 draws) went from a median of 34.0 to 31.8 ms with it, and the lighter one (under 6,500 draws) from 26.8 to 26.3. In the repo's d3d12/docs/findings.md it measured +0.16 and +0.10 ms on the 4060 Ti / 7600X (d62), and +0.11 and -0.46 ms in the later repeat (d217, d218). That fits a CPU with no free core: what the list threads save goes to the threads the frame waits for.
  • Content tables: lean towards a small gain, within about 1.5 standard errors.
  • Alias answers: nothing measurable.
  • Indexed heap spans: -0.36 +-0.58 ms here, standing, against -1.64 +-0.35 and -1.61 +-0.48 standing in the same file (d212, d213). Smaller here, but the two differ by under 2 combined standard errors, so not clearly different.

2. The title's Sleep(0) wait (section 2 of the issue) costs no frames: ruled out

Section 2 of the issue called the busiest title thread's Sleep(0) spin a possible cost. I tested that directly, and it is not.

What it is, from the disassembly:

  • At the end of each frame (rva 0x2474740) the title keeps the fence points of its last two frames in a ring of two and waits for the older one, so the card is at most one frame behind.
  • The token is 64 bits: the top 8 name the queue, the low 56 the point (0x4fb0a50).
  • The wait (0x4fb0a90 -> 0x4fb0ad0) reads the fence's value at the address its slot 0x60 gives (fence.rs gpu_address), with monitorx/mwaitx and Sleep(0) between reads. The end-of-frame wait goes through the path with Sleep(0).

The test was a local patch that replaces the title's entry (0x4fb0a90, 14-byte absolute jump, checked against the build's hash and bytes). It sleeps on the fence's value with WaitOnAddress, which fence::set's WakeByAddressAll already wakes, and falls back to the title's own inner wait when turned off.

LEONIDA_AB by turns, 10 min, 76 on/off triples: the median frame changed by +0.07 +-0.35 ms with the hook on.

Two separate 4-min runs, median of the 5-s lines:

View Without the hook With the hook
Lighter 38.8 fps (27 lines) 38.7 fps (31 lines)
Heavier 31.1 fps (17 lines) 31.3 fps (15 lines)

No effect: the median does not move, and the 0.2 fps in the heavier view is within the noise of two short runs. The same A/B's mean (-1.76 +-1.53 ms) and p90 (-1.85 +-1.70) lean negative, but each is about one standard error and far noisier than the median, as a few slow phases sway them; the submitting thread's own work changed by -0.26 +-0.17 ms. None of it is a gain I would claim. The likely reason: Sleep(0) already gives the processor to any ready thread, so the spin's kernel time is overhead on its own thread, not a core taken from the runtime's threads. Section 3 shows what the frame does wait for. Not worth anyone's time unless a later profile shows otherwise.

3. The submitting thread is not what the frame waits for here

LEONIDA_TIMELINE (20 frames at 200 s, 30.5 ms a frame) and LEONIDA_PROFILE on leonida-submit (every 2 ms, 200-260 s, 23,204 samples), separate runs. I did not check which of the two views the 20 frames fell in.

The chain back through all frames, per frame, by cause:

Cause ms a frame
Title threads outside our spans (the nine largest; 6.79 on one of them) about 12.1
Recording: inside our list calls 6.72
A long list call 2.73
Woken, not running yet 0.92
The card running submissions 0.83
A landing's job 0.63
A wait nobody seen here ended (Sleep) 0.63
Submit: the lists' steps 0.52
  • leonida-submit ran 22.1 ms and waited 8.9 ms of each 30.5 ms frame.
  • The card ran 20.1 ms a frame (19.1 submissions) and stood idle 10.4 ms between them.
  • The six list threads each ran 25.0 to 26.9 ms a frame.

Where leonida-submit spends its samples (inclusive):

Share What
26.8 % wait_on_address (9.1 % of all samples inside shadow::wide, waiting for helpers; the rest outside it)
25.2 % shadow::wide (the work spread over threads, its own share included)
19.1 % submit, of which about 8 % is watch::kernel_written (6.8 % through watch::ask_ahead), in ntdll
18.8 % Batch::refresh_front
8.2 % Batch::fill
7.5 % card_before (closure)

The NVIDIA driver is the top module for 12.7 % of all samples. So with the view cache on, the submitting thread waits 8.9 ms a frame; taking out its waits for helpers, about 5 to 6 ms of that is slack. The chain is the title's own threads and the list threads' recording.

4. List threads: half their time is table setup for indirect executions

LEONIDA_PROFILE on leonida-list (every 2 ms, 200-260 s, 138,480 samples over the six threads). Inclusive shares:

Share What
67.8 % State::bind (all callers)
62.8 % list::execute_indirect closure
49.3 % State::tables
22.2 % HostHeap::make_listed
10.8 % make_twinned_info (4.1 % in the driver's CreateShaderResourceView)
5.1 % draw::readable
3.4 % keep_ref
  • Locks: Mutex::lock 6.9 % self, Mutex::unlock 2.6 %, RwLock::read 1.4 %. About 11 % in all, well under the ETW figure in the issue (about 27 %). The two tools count differently, so I would not call that a measured drop.
  • The biggest single lock site is in State::tables (draw.rs, the listed_view branch): list.deferred_steps() takes the list's deferred mutex only to read copies.len(), for each view not yet known ready. That is 1.9 % of the list threads' samples.
  • The top module is the NVIDIA driver for 13.8 % of samples, D3D12Core 4.6 %, d3d12 3.3 %.
  • About 7 % is a wait with nothing of ours above it on the stack: the list threads are close to saturated.

5. Two local experiments on the list threads: no measurable gain

Both behind switches, off by default, measured with LEONIDA_AB in one 10-min run (4 s turns, 152 world phases, 37 complete rounds of 4). Median frame time, on minus off:

Switch All Lighter view Heavier view
Views kept across recordings -0.10 +-0.22 ms -0.04 +-0.18 -0.10 +-0.19
deferred_steps() without the lock -0.06 +-0.36 ms -0.35 +-0.30 -0.15 +-0.21
  • Views kept across recordings. make_listed clears a thread's ListViews at every new recording. With the switch, a thread kept them for up to 512 recordings, or until three quarters of the slots were used. It used one again only for a plain View::Shader of a title texture, only if made_copy gave the same host copy (Weak pointer compare) and the first level shown was the same, and with listed.ready, tabled and aliased reset. Every other view was made anew as now, in a new slot. Used again: 16.5 million; made anew: 31.9 million. So about a third reused, and the frame did not move. My guess is that most of the rest are placed-memory views, which this left alone, but I did not count by kind. In the part of the run I watched there was nothing beyond the usual flicker.
  • deferred_steps() without the lock. The list's step count is stored in an atomic as the deferred guard is dropped, under the lock, and deferred_steps() reads that. Nothing measurable.

The list threads' cost is spread thin: no single part of it moves the frame on its own here.

6. 20fe0c754 (pools grown with their lock released)

A 6-min run standing, 5-s frame lines split by view:

Build Lighter view Heavier view
20fe0c754 25.0 ms median (48 lines) 30.9 ms (24 lines)
f9f3ec4c6, profile run (sampler on) 25.3 ms (42) 30.8 ms (29)
f9f3ec4c6, timeline run 24.9 ms (49) 29.9 ms (22)

No change in frame time, as expected. Its own line for the run: 79 blocks made in 288 ms (longest 24.3 ms), and 977 waits for their pools, 2 ms in all (longest 0.6 ms). Before this change a thread that wanted the pool while a block was being made waited behind its lock; now those waits came to 2 ms in all. If that shows anywhere it should be as fewer hitches, not in the 5-s medians.

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7282351109 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2707#issuecomment-7282351109). Originally posted by [Yizzii](https://github.com/Yizzii) on 2026-11-30T15:03:08Z. --- Follow-up, same PC (RTX 5070 Ti, Ryzen 7 9800X3D), standing at the same spot, frame generation off. Sections 1 and 2 are on `d367675c7`, 3 and 4 on `f9f3ec4c6`, 5 and 6 on `20fe0c754`. From section 3 on, every run has `LEONIDA_VIEW_CACHE=1` (section 1). ### 1. `LEONIDA_VIEW_CACHE` helps on this CPU `LEONIDA_AB` (by turns of 4 s), two runs, 186 and 228 world phases. For each switch, the mean per 8-phase round of (phases on) - (phases off), with the standard error over the rounds, for the median frame time: | Switch | Run 1 (10 min, 23 rounds) | Run 2 (15 min, 28 rounds) | |---|---|---| | `LEONIDA_VIEW_CACHE` | **-0.87 +-0.24 ms** | **-1.17 +-0.21 ms** (mean -1.05 +-0.23, p90 -0.98 +-0.37) | | `LEONIDA_CONTENT_TABLES` | -0.68 +-0.70 | -0.54 +-0.37 (p90 -1.02 +-0.53) | | `LEONIDA_ALIAS_QUICK` | -0.23 +-0.37 | (not in run 2) | | `LEONIDA_INDEX_HEAP_SPANS` | (not in run 1) | -0.36 +-0.58 | - **View cache**: about 1 ms a frame in both runs (3.6 and 5.6 standard errors). By view, in run 2 the heavier view (more than 8,000 draws) went from a median of 34.0 to 31.8 ms with it, and the lighter one (under 6,500 draws) from 26.8 to 26.3. In the repo's `d3d12/docs/findings.md` it measured +0.16 and +0.10 ms on the 4060 Ti / 7600X (d62), and +0.11 and -0.46 ms in the later repeat (d217, d218). That fits a CPU with no free core: what the list threads save goes to the threads the frame waits for. - **Content tables**: lean towards a small gain, within about 1.5 standard errors. - **Alias answers**: nothing measurable. - **Indexed heap spans**: -0.36 +-0.58 ms here, standing, against -1.64 +-0.35 and -1.61 +-0.48 standing in the same file (d212, d213). Smaller here, but the two differ by under 2 combined standard errors, so not clearly different. ### 2. The title's `Sleep(0)` wait (section 2 of the issue) costs no frames: ruled out Section 2 of the issue called the busiest title thread's `Sleep(0)` spin a possible cost. I tested that directly, and it is not. What it is, from the disassembly: - At the end of each frame (rva `0x2474740`) the title keeps the fence points of its last two frames in a ring of two and waits for the older one, so the card is at most one frame behind. - The token is 64 bits: the top 8 name the queue, the low 56 the point (`0x4fb0a50`). - The wait (`0x4fb0a90` -> `0x4fb0ad0`) reads the fence's value at the address its slot `0x60` gives (`fence.rs` `gpu_address`), with `monitorx`/`mwaitx` and `Sleep(0)` between reads. The end-of-frame wait goes through the path with `Sleep(0)`. The test was a local patch that replaces the title's entry (`0x4fb0a90`, 14-byte absolute jump, checked against the build's hash and bytes). It sleeps on the fence's value with `WaitOnAddress`, which `fence::set`'s `WakeByAddressAll` already wakes, and falls back to the title's own inner wait when turned off. `LEONIDA_AB` by turns, 10 min, 76 on/off triples: the median frame changed by **+0.07 +-0.35 ms** with the hook on. Two separate 4-min runs, median of the 5-s lines: | View | Without the hook | With the hook | |---|---|---| | Lighter | 38.8 fps (27 lines) | 38.7 fps (31 lines) | | Heavier | 31.1 fps (17 lines) | 31.3 fps (15 lines) | No effect: the median does not move, and the 0.2 fps in the heavier view is within the noise of two short runs. The same A/B's mean (-1.76 +-1.53 ms) and p90 (-1.85 +-1.70) lean negative, but each is about one standard error and far noisier than the median, as a few slow phases sway them; the submitting thread's own work changed by -0.26 +-0.17 ms. None of it is a gain I would claim. The likely reason: `Sleep(0)` already gives the processor to any ready thread, so the spin's kernel time is overhead on its own thread, not a core taken from the runtime's threads. Section 3 shows what the frame does wait for. Not worth anyone's time unless a later profile shows otherwise. ### 3. The submitting thread is not what the frame waits for here `LEONIDA_TIMELINE` (20 frames at 200 s, 30.5 ms a frame) and `LEONIDA_PROFILE` on `leonida-submit` (every 2 ms, 200-260 s, 23,204 samples), separate runs. I did not check which of the two views the 20 frames fell in. The chain back through all frames, per frame, by cause: | Cause | ms a frame | |---|---| | Title threads outside our spans (the nine largest; 6.79 on one of them) | about 12.1 | | Recording: inside our list calls | 6.72 | | A long list call | 2.73 | | Woken, not running yet | 0.92 | | The card running submissions | 0.83 | | A landing's job | 0.63 | | A wait nobody seen here ended (Sleep) | 0.63 | | Submit: the lists' steps | 0.52 | - `leonida-submit` ran 22.1 ms and waited 8.9 ms of each 30.5 ms frame. - The card ran 20.1 ms a frame (19.1 submissions) and stood idle 10.4 ms between them. - The six list threads each ran 25.0 to 26.9 ms a frame. Where `leonida-submit` spends its samples (inclusive): | Share | What | |---|---| | 26.8 % | `wait_on_address` (9.1 % of all samples inside `shadow::wide`, waiting for helpers; the rest outside it) | | 25.2 % | `shadow::wide` (the work spread over threads, its own share included) | | 19.1 % | `submit`, of which about 8 % is `watch::kernel_written` (6.8 % through `watch::ask_ahead`), in `ntdll` | | 18.8 % | `Batch::refresh_front` | | 8.2 % | `Batch::fill` | | 7.5 % | `card_before` (closure) | The NVIDIA driver is the top module for 12.7 % of all samples. So with the view cache on, the submitting thread waits 8.9 ms a frame; taking out its waits for helpers, about 5 to 6 ms of that is slack. The chain is the title's own threads and the list threads' recording. ### 4. List threads: half their time is table setup for indirect executions `LEONIDA_PROFILE` on `leonida-list` (every 2 ms, 200-260 s, 138,480 samples over the six threads). Inclusive shares: | Share | What | |---|---| | 67.8 % | `State::bind` (all callers) | | 62.8 % | `list::execute_indirect` closure | | 49.3 % | `State::tables` | | 22.2 % | `HostHeap::make_listed` | | 10.8 % | `make_twinned_info` (4.1 % in the driver's `CreateShaderResourceView`) | | 5.1 % | `draw::readable` | | 3.4 % | `keep_ref` | - Locks: `Mutex::lock` 6.9 % self, `Mutex::unlock` 2.6 %, `RwLock::read` 1.4 %. About 11 % in all, well under the ETW figure in the issue (about 27 %). The two tools count differently, so I would not call that a measured drop. - The biggest single lock site is in `State::tables` (draw.rs, the `listed_view` branch): `list.deferred_steps()` takes the list's `deferred` mutex only to read `copies.len()`, for each view not yet known ready. That is 1.9 % of the list threads' samples. - The top module is the NVIDIA driver for 13.8 % of samples, `D3D12Core` 4.6 %, `d3d12` 3.3 %. - About 7 % is a wait with nothing of ours above it on the stack: the list threads are close to saturated. ### 5. Two local experiments on the list threads: no measurable gain Both behind switches, off by default, measured with `LEONIDA_AB` in one 10-min run (4 s turns, 152 world phases, 37 complete rounds of 4). Median frame time, on minus off: | Switch | All | Lighter view | Heavier view | |---|---|---|---| | Views kept across recordings | -0.10 +-0.22 ms | -0.04 +-0.18 | -0.10 +-0.19 | | `deferred_steps()` without the lock | -0.06 +-0.36 ms | -0.35 +-0.30 | -0.15 +-0.21 | - **Views kept across recordings.** `make_listed` clears a thread's `ListViews` at every new recording. With the switch, a thread kept them for up to 512 recordings, or until three quarters of the slots were used. It used one again only for a plain `View::Shader` of a title texture, only if `made_copy` gave the same host copy (`Weak` pointer compare) and the first level shown was the same, and with `listed.ready`, `tabled` and `aliased` reset. Every other view was made anew as now, in a new slot. Used again: 16.5 million; made anew: 31.9 million. So about a third reused, and the frame did not move. My guess is that most of the rest are placed-memory views, which this left alone, but I did not count by kind. In the part of the run I watched there was nothing beyond the usual flicker. - **`deferred_steps()` without the lock.** The list's step count is stored in an atomic as the `deferred` guard is dropped, under the lock, and `deferred_steps()` reads that. Nothing measurable. The list threads' cost is spread thin: no single part of it moves the frame on its own here. ### 6. `20fe0c754` (pools grown with their lock released) A 6-min run standing, 5-s frame lines split by view: | Build | Lighter view | Heavier view | |---|---|---| | `20fe0c754` | 25.0 ms median (48 lines) | 30.9 ms (24 lines) | | `f9f3ec4c6`, profile run (sampler on) | 25.3 ms (42) | 30.8 ms (29) | | `f9f3ec4c6`, timeline run | 24.9 ms (49) | 29.9 ms (22) | No change in frame time, as expected. Its own line for the run: 79 blocks made in 288 ms (longest 24.3 ms), and 977 waits for their pools, 2 ms in all (longest 0.6 ms). Before this change a thread that wanted the pool while a block was being made waited behind its lock; now those waits came to 2 ms in all. If that shows anywhere it should be as fewer hitches, not in the 5-s medians.
zmasi commented 2026-11-30 16:41:39 +00:00 (Migrated from github.com)
Author
Contributor

Imported from ubiquitarianism/leonida. Originally posted by zmasi on 2026-11-30T16:41:39Z.


Opened #2764 addressing the four list-thread lock contention hotspots in section 3 (descriptor::view_at, descriptor::host::table_r9g9b9e5_views, descriptor::host::placed_texture / resource::texture_at + resource::want_level, and resource::hosted) behind LEONIDA_LIST_LOCK_FAST (on by default; =0 negative control): 300.0 -> 31.3 ns/draw (9.60x) no-r9 and 301.8 -> 45.1 ns/draw (6.69x) combined across 6 recording threads.

AI-assisted: GPT-6.2 Astra and Claude / Gemini 4 Neon, verified with Gemini 4 Carbon (High), reviewed with Gemini 4 Neon (XHigh).

<!-- greyfinch-sync:ubiquitarianism/leonida:comment:7285080452 --> Imported from [ubiquitarianism/leonida](https://github.com/ProjectLeonida/mandy/issues/2707#issuecomment-7285080452). Originally posted by [zmasi](https://github.com/zmasi) on 2026-11-30T16:41:39Z. --- Opened #2764 addressing the four list-thread lock contention hotspots in section 3 (`descriptor::view_at`, `descriptor::host::table_r9g9b9e5_views`, `descriptor::host::placed_texture` / `resource::texture_at` + `resource::want_level`, and `resource::hosted`) behind `LEONIDA_LIST_LOCK_FAST` (on by default; `=0` negative control): `300.0 -> 31.3 ns/draw` (`9.60x`) `no-r9` and `301.8 -> 45.1 ns/draw` (`6.69x`) combined across 6 recording threads. AI-assisted: GPT-6.2 Astra and Claude / Gemini 4 Neon, verified with Gemini 4 Carbon (High), reviewed with Gemini 4 Neon (XHigh).
Sign in to join this conversation.
No labels
No milestone
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.

Reference
ProjectLeonida/mandy#2707
No description provided.