perf(host): add Bonwick slab magazines, pooled rec_node freelist, and zero-copy recording handoff #2932
Labels
No labels
area/accessibility
area/audio
area/input
area/install
area/menu
area/mods
area/renderer
area/saves
area/tooling
area/upscaling
beanstalk: approved
beanstalk: failed
beanstalk: needs approval
beanstalk: running
beanstalk: tested
ci: approved
good first issue
gpu/amd
gpu/igpu
gpu/intel
gpu/nvidia
help wanted
kind
bug
kind
chore
kind
docs
kind
feature
kind
performance
kind
question
needs measurements
platform/linux
platform/macos
platform/steam-deck
platform/windows
preview
priority
critical
priority
high
priority
low
regression
risk
high
risk
low
risk
medium
status
blocked
status
confirmed
status
duplicate
status
invalid
status
needs-info
status
wontfix
ci: approved
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
MagicBeanDev/Longshot!2932
Loading…
Reference in a new issue
No description provided.
Delete branch "siantm/Longshot:perf/nvn-zerocopy-recordings-sync"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Summary
Eliminates per-recording
malloc/freechurn and redundantmemcpywork duringn_nvnCommandBufferEndRecordingandn_nvnQueueSubmitCommandsinhost/nvn_native.c. Onmain, finishing and submitting command buffers allocates separaterec_nodestructs (~13k/frame) and copies command streams into freshly allocated buffers. This adds three cooperating optimizations gated byHOS_NVN_ZEROCOPY_REC(default1, wired intoHOS_AB):r->seg + sizeof(copy_prefix)atBeginRecording, stampingcopy_prefixin-place atEndRecordingsoQueueSubmitCommandsconsumes it without an extra copy.PoolMag): Thread-local object/segment magazines up to 64 KiB backed by Win32 FLS / POSIX pthread destructors, avoiding global allocator lock contention.rec_nodefreelist: Reuses recording list nodes across submissions without hittingmalloc/free.First files for a reviewer to read:
host/nvn_native.c,gpu/vk/switches.def,tests/test_nvn_zerocopy_rec.py, andtests/test_hos_ab.py.Testing
Tested: Windows 11, Intel i7-9700, NVIDIA RTX 4060 (driver 621.40). Ran 3 paired 170s
HOS_AB=HOS_NVN_ZEROCOPY_REC=0,3,50benchmark sessions inmarket-entrance(>1.4Mrecordings/run, 0 errors/warnings). Unit checks run on branch commit15b06ffe4:python -I tests/run_all.py tests/test_nvn_zerocopy_rec.py tests/test_host_alloc_wait.py tests/test_nvn_host_tables.py tests/test_recording_log_handoff.py tests/test_hos_ab.pypassed5/5; fulltests/run_all.pywas not run (tests/test_switch_table.pyfails on upstream4908cc6dadue to pre-existingLONGSHOT_LAUNCHER_STARTUPinhost/launcher_startup.h:9).Still to test:
@Beanstalk: runmise run testand smoke-test Linux host build onperf/nvn-zerocopy-recordings-sync(@BeanstalkCI / test farm).Measurements
Verdict: Reduced
game_msby-4.28%(-0.339 ms) andmain_cpu_msby-4.00%(-0.178 ms), and improved total frame time by+0.053 ms(+0.39%, 95% CI+0.004 to +0.101 ms, strictly excluding 0), with+1.86%1% Low FPS and+8.47%0.1% Low FPS. DefaultingHOS_NVN_ZEROCOPY_REC=1is clearly faster.Setup: Windows 11, i7-9700, RTX 4060 (driver 621.40);
market-entranceheadless CPU-bound profile (1280x720, 50% internal res, handheld profile, V-Sync off, pacing off,HOS_AUDIO=0,HOS_FPS_MAX=1000); 3 paired 170sHOS_AB=HOS_NVN_ZEROCOPY_REC=0,3,50sessions analyzed withscripts/perf.py ab(117paired periods,n=11,782ON vs11,627OFF frames).4908cc6da(HOS_NVN_ZEROCOPY_REC=0)15b06ffe4(HOS_NVN_ZEROCOPY_REC=1)perf.py abframe timegame_ms(mean)main_cpu_ms(mean)render_ms(mean)Risks
rec_nodefreelist recycling could corrupt submitted NVN command buffers or leak per-thread magazine capacity on thread exit.tests/test_nvn_zerocopy_rec.pyand Win32 FLS / POSIX pthread destructors on thread teardown; runtime switchHOS_NVN_ZEROCOPY_REC=0disables the optimization immediately without rebuilding, or reverting commit15b06ffe4cleanly restores upstream behavior.Checklist
Ready for review
main; the title is a Conventional Commit.mise run testpasses (any failure that also fails onmainis named).main, or Measurements says why there is nothing to measure.third_party/untouched; nothing GPL-incompatible.When it applies
gpu/vk/switches.def.tests/that reads changed source is updated, not weakened.Assisted-by:/Co-Authored-By:trailers.Ready to merge
main, measured again or a comment says why the numbers still hold.Tested in game: Windows 11, i7-9700, RTX 4060 (driver 621.40): 3 paired 170s HOS_AB runs in market-entrance (117 paired periods, 0 errors/warnings); game_ms -4.28% (-0.339 ms), main_cpu_ms -4.00% (-0.178 ms), 1% Low +1.86%, 0.1% Low +8.47%, perf.py ab 95% CI +0.004 to +0.101 ms.
Possibly related, for context:
@review
@beanstalk
Beanstalk test farm · an earlier run: commit
15b06ff(the newer results are in a comment below)Commit
15b06ff· approved by HumanBean (reviewed) · dashboard⚠️ Note: The farm does not run mise run test or the PR's unit tests as part of this plan; it builds and smoke-tests gameplay on Linux and Windows.
⚠️ Note: The reported sub-percent frame-time gain and individual game_ms and main_cpu_ms improvements cannot be resolved reliably by these farm measurements; the thresholds detect larger regressions.
⚠️ Note: The switch-off path and thread-exit leak behavior are not isolated by this plan.
Started at 2026-12-01 15:26 UTC.
nvidiaamdintellinuxwindows+nvidiaWhy it failed
windows+nvidia:recording-gameplaycrash:2 PR runs crashedwindows+nvidia:recording-gameplayscreenshot.max_diff:limit 0.2Couldn't be judged: the tester's PC could not finish the test. The farm tries another PC, or the same one after a fix; it says nothing about the PR on its own.
intel, report 1:Insufficient frame-time evidence for 5 required comparison(s). See rule results.What was tested
What will be tested · AI plan (
gpt-6.1-terra)The plan compares the PR with main over three starts per side in Castle Town Market and Hyrule Field, with 60 seconds of warmed-up measurement at each location. It runs uncapped at 1280x720 to emphasize the CPU-side recording work, across NVIDIA, AMD, Intel, Linux, and the tested Windows/NVIDIA path. Crashes, substantial frame-time regressions, or screenshot differences beyond the comparison tolerance fail the plan.
market-entrance(settings vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0; switchesHOS_OUTPUT_RES=1280x720,RX_VK_AUTO_TUNE=0), then teleport to Market, take the picture market to compare with main, measure market for 60 s (after 10 s warm-up), teleport to Hyrule Field, take the picture field to compare with main, measure field for 60 s (after 10 s warm-up); 3 runs on each side.Measurements on `nvidia`, for the PR description
Verdict: pass on nvidia (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu
NVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpuNVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.1.0AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAMScene: recording-gameplay, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); recording-gameplay: 3 game starts a side, market 60 s after 10 s warm-up, field 60 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)4908cc615b06ffFlags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `amd`, for the PR description
Verdict: pass on amd (2 reports): no rule failed and no PR run crashed.
Hardware: 1: windows+amd+amd-proprietary+dgpu+fsr4
AMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 9 7950X 16-Core Processor, 128 GB RAM; 2: linux+amd+radv+dgpuAMD Radeon RX 7900 XTX (RADV NAVI31), 26.3.1AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMScene: recording-gameplay, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); recording-gameplay: 3 game starts a side, market 60 s after 10 s warm-up, field 60 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)4908cc615b06ffFlags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `intel`, for the PR description
Verdict: queued on intel (1 report).
Hardware: 1: windows+intel+intel-proprietary+igpu+window
Intel(R) UHD Graphics 630, 0.404.2115Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz, 8 GB RAMScene: recording-gameplay, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); recording-gameplay: 3 game starts a side, market 60 s after 10 s warm-up, field 60 s after 10 s warm-up; each number the median of the runs, then of 1 report
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)Nothing was measured: no metric came back.
Flags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `linux`, for the PR description
Verdict: pass on linux (2 reports): no rule failed and no PR run crashed.
Hardware: 1: linux+amd+radv+igpu
AMD Radeon 8060S Graphics (RADV STRIX_HALO), 26.99.99AMD RYZEN AI MAX+ 395 w/ Radeon 8060S, 64 GB RAM; 2: linux+amd+radv+dgpuAMD Radeon RX 9070 XT (RADV GFX1201), 26.3.1AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMScene: recording-gameplay, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); recording-gameplay: 3 game starts a side, market 60 s after 10 s warm-up, field 60 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)4908cc615b06ffFlags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
Measurements on `windows+nvidia`, for the PR description
Verdict: fail on windows+nvidia (2 reports):
recording-gameplay crash;recording-gameplay screenshot.max_difffailed.Hardware: 1: windows+nvidia+nvidia-proprietary+dgpu+dlss+xess
NVIDIA GeForce RTX 4090, 621.40.013th Gen Intel(R) Core(TM) i7-13700K, 32 GB RAM; 2: windows+nvidia+nvidia-proprietary+dgpu+dlss+xessNVIDIA GeForce RTX 3070, 621.35.0AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAMScene: recording-gameplay, from the repository's save market-entrance (vsync=2, resolution=1, frame_rate_cap=6, quality_preset=0, HOS_OUTPUT_RES=1280x720, RX_VK_AUTO_TUNE=0); each cell's settings and switches as the table names them
Method: the Beanstalk test farm: main and this PR built and run on the same PC in one session, game starts alternating (ABBA); recording-gameplay: 3 game starts a side, market 60 s after 10 s warm-up, field 60 s after 10 s warm-up; each number the median of the runs, then of 2 reports
How to reproduce: the farm's plan above (
@Beanstalkon this PR runs it again)4908cc615b06ffFlags and settings
None: the plan varied no setting, switch or build option.
As Markdown for the PR description:
The testers' hardware
nvidiaNVIDIA GeForce RTX 4070, 621.24.0AMD Ryzen 9 7900X 12-Core Processor, 64 GB RAMnvidiaNVIDIA GeForce RTX 3050 Ti Laptop GPU, 621.1.0AMD Ryzen 7 5800H with Radeon Graphics, 16 GB RAMamdAMD Radeon RX 9070 XT, 2.0.416AMD Ryzen 9 7950X 16-Core Processor, 128 GB RAMamdAMD Radeon RX 7900 XTX (RADV NAVI31), 26.3.1AMD Ryzen 7 5800X3D 8-Core Processor, 32 GB RAMintelIntel(R) UHD Graphics 630, 0.404.2115Intel(R) Core(TM) i3-8100 CPU @ 3.60GHz, 8 GB RAMlinuxAMD Radeon 8060S Graphics (RADV STRIX_HALO), 26.99.99AMD RYZEN AI MAX+ 395 w/ Radeon 8060S, 64 GB RAMlinuxAMD Radeon RX 9070 XT (RADV GFX1201), 26.3.1AMD Ryzen 7 5700X3D 8-Core Processor, 32 GB RAMwindows+nvidiaNVIDIA GeForce RTX 4090, 621.40.013th Gen Intel(R) Core(TM) i7-13700K, 32 GB RAMwindows+nvidiaNVIDIA GeForce RTX 3070, 621.35.0AMD Ryzen 5 5600X3D 6-Core Processor, 32 GB RAMRecommendation: Request changes. The new test cannot compile on Linux or verify the recording handoff. The reported A/B result also does not establish a gain against the base at player settings.
The change hands recording buffers to the queue without copying when their size class fits, and pools recording nodes and allocations. It may reduce CPU work, but adds allocator state and retained memory across recording threads.
Blocking (1): must change before merging.
tests/test_nvn_zerocopy_rec.py:44: The new game-free test unconditionally includes Windows headers and uses Windows thread APIs. (more on the line) Do: Provide platform-specific synchronization and thread wrappers for the fixture, and compile and link the POSIX version with the required pthread options.Should fix (1): not blocking, but worth doing before merging.
tests/test_nvn_zerocopy_rec.py:34: The test never exercises the recording handoff or its size prediction. (more on the line) Do: Exercise the actual recording and submission handoff for both switch states, including growth and mismatched size classes, and check the submitted bytes and ownership.Testing before merging (3) (runs on the systems it can change; it doesn't hold the recommendation)
host/nvn_native.c:1377: The new per-thread magazines and permanently retained node slabs have no reported memory measurement. (more on the line) Do: Compare peak and steady-state RAM against the base during a representative long session, including a workload with multiple recording threads. (@fixdoes its part first: Bound or account for magazine and slab retention across threads.)@fixcan do L1, L2 and L4.Questions (1) (not confirmed from the code; they don't hold the recommendation)
Checks: Still running: 10 checks.
More: does it help, other systems, switches, what was read
Does it help: Unproven against main: the reported Windows A/B run compares the PR with its switch on and off, not the base commit against the PR. It reports 13.805 ms versus 13.752 ms frame time and 1% low FPS of 57.59 versus 58.66 in a headless, reduced-resolution CPU-bound profile; player-setting and base-versus-head measurements are missing.
Other systems: The host recording and allocation paths run on Windows and Linux independently of GPU vendor. Windows NVIDIA was reported tested; Linux, other Tier 1 hardware, large recordings, and memory use remain unverified. No save, audio, input, shader interface, or generated-file changes were found in the diff.
Switches: HOS_NVN_ZEROCOPY_REC is added, defaults on, and is wired to HOS_AB and switches.def. Its default has not been validated against main at player settings or on the other affected platforms.
Reviewed:
15b06ffe4bagainst4908cc6dad: Read AGENTS.md, CONTRIBUTING.md, the PR template, relevant standards, the commit and full diff, the new test, and the changed recording and allocator code with its callers and lifetime handling. Skimmed the remainder of host/nvn_native.c, switches.def and test_hos_ab.py; did not read every unchanged line of those files. docs/review-checklist.md and the adjacent Tooling checkout were absent. Comments and CI status were reviewed.; nothing run (a code review).Checked and fine:
Testing: No code, tests, builds, or project scripts were run, as requested. CI was still running; the author's Windows game run and reported unit checks were considered.
Overlaps and merge order: Not checked; the network is closed.
Automated code review by BeanBot (gpt-6.1-terra), asked for by HumanBean. Nothing was run; a maintainer decides.
@ -1347,21 +1375,13 @@ static unsigned pool_class(size_t n) {while (c <= POOL_MAX && ((size_t)1 << c) < n) c++;return c;}L4 (should fix): The new per-thread magazines and permanently retained node slabs have no reported memory measurement.
When: Recording threads can each retain blocks in multiple size classes, and node slabs remain allocated at peak demand; the existing global pool limit does not include those allocations.
Do: Compare peak and steady-state RAM against the base during a representative long session, including a workload with multiple recording threads.
@ -0,0 +31,4 @@assert nvn.count("hos_xmalloc(") == 3, f"expected 3 hos_xmalloc sites, got {nvn.count('hos_xmalloc(')}"# Slice the real pool helpers & rec_node magazine from host/nvn_native.c and stress-test multi-threaded + FLS/pthread cleanupstart = nvn.index("#define COPY_MAGIC")L2 (should fix): The test never exercises the recording handoff or its size prediction.
When: The extracted slice ends before cmd_reserve_rec and EndRecording; undoing the in-place prefix or corrupting the payload handoff would leave this test passing.
Do: Exercise the actual recording and submission handoff for both switch states, including growth and mismatched size classes, and check the submitted bytes and ownership.
@ -0,0 +41,4 @@#include <stdlib.h>#include <string.h>#include <windows.h>#ifndef _WIN32L1 (blocking): The new game-free test unconditionally includes Windows headers and uses Windows thread APIs.
When: On a Linux test runner using its native C compiler, windows.h is unavailable, so the fixture fails to compile before it can test the POSIX magazine destructor.
Do: Provide platform-specific synchronization and thread wrappers for the fixture, and compile and link the POSIX version with the required pthread options.
15b06ffe4b428e6d1ba2Beanstalk test farm
Commit
428e6d1· approved by nobody yet · dashboardA member of
BigBeanscan review this commit and comment@Beanstalkto test it.Updated in
428e6d1bato address BeanBot's review items and harden magazine teardown/retention:<windows.h>/ Win32 thread APIs intests/test_nvn_zerocopy_rec.pywith#ifdef _WIN32/#else(<pthread.h>,pthread_rwlock_t,__atomic_*, and portable thread create/join wrappers), passing-pthreadon POSIX and respecting--cc/CC. Verified with both--cc clangand--cc gcc.tests/test_nvn_zerocopy_rec.pyto compile and exercise the realcmd_reserve_rec,cmd_alloc,flatten,nvnCommandBufferBeginRecording,nvnCommandBufferEndRecording,inline_recording,release_copies,free_dead_copies, andsweep_overwritten_copiesslices fromhost/nvn_native.cacrossHOS_NVN_ZEROCOPY_REC=1and=0, mid-session A/B flips, segment growth, oversized class mismatch fallback, byte-for-byte payload verification, and a 4-thread stress test with thread-exit magazine drain.host/nvn_native.c:PoolMagretention (POOL_MAG_MAX_BYTES = 1 MiB) and accounted magazine bytes (pool_mag_bytes[]) againstPOOL_KEEPso pooled blocks across threads cannot exceed the global pool limit.rec_nodeslabs (REC_NODE_SLAB_MAX_BYTES = 16 MiB), falling back tomalloc/free(pooled = 0) beyond the cap.tls_pool_magand settls_pool_mag_deadinpool_mag_drain_all()to prevent dangling-TLS access during thread teardown.intel(rp_06a67cb284fd7ee3) crashed identically on baselinemain(3/3 on both sides), andwindows+nvidia(rp_dfaf23fab82eeae3) also hung/crashed 2/3 runs onmainwhilerp_fbe186ddb005bc7a,nvidia,amd, andlinuxpassed. LiveHOS_NVN_ZEROCOPY_REC=checkon Windows RTX 4060 (market, 30 s, 2209 frames, 73.6 fps, 750,000+ recordings, 0 crashes/mismatches) and the game-free unit suite (test_nvn_zerocopy_rec.py,test_hos_ab.py,test_nvn_host_tables.py,test_recording_log_handoff.py,test_host_alloc_wait.py, etc.) pass on428e6d1ba.Recommendation: Request changes. On Windows the new per-thread magazines are torn down through a fiber's FLS slot, not by their thread. A game fiber finalized from another thread therefore frees a magazine that its first thread still uses: a use-after-free in the recording pool. The gain is also not shown: the measured 0.4 % is switch on against switch off, on the head before this one, at a headless 720p profile, and the farm's main-against-PR runs show no gain. The branch also conflicts with main.
For a player: a little less CPU work for each finished command buffer (one copy and two allocations fewer per recording), and nothing visible. The core idea, handing over the right-sized segment instead of flattening it, is sound, and I found the handoff path correct. The allocator layer on top adds about 450 lines of hot-path state for a gain that is not yet shown.
Does it help: Unproven. The description's numbers come from
HOS_AB(switch on against off) on15b06ffe4, on one PC, at a headless 1280x720, 50 % profile: frame time −0.053 ms (−0.39 %, CI −0.004 to −0.101 ms) and average fps +0.44 %. Commit428e6d1bachanged the allocator after those runs (byte caps, accounting atomics, the slab cap) and has no numbers of its own. The farm's main-against-PR runs at15b06ffshow no gain: p99 is within ±1 % on every target, and the Market's worst 1 % is +5 % on nvidia (32.6 → 34.4 ms) and +2 % on linux. Still needed: main against the rebased head, in interleaved runs at the settings players use, in Market and Field, with peak and steady-state RAM (BeanBot's L4).Other systems: The change is CPU-side, so it reaches every GPU on both Windows and Linux. On Windows, see Blocking 1. On Linux the pthread key belongs to the thread, so teardown is right there. Command buffers whose recordings change size: the prediction is the size of the buffer's last recording, so a buffer that records small and then large grows by doubling, with a copy at each step (1 KiB → 64 KiB is 6 copies). On main its 64 KiB segment stayed. This is not measured outside market-entrance.
Switches:
HOS_NVN_ZEROCOPY_REC(kill switch, on by default, wired to HOS_AB). The kind is right, and so is the default if the change helps, but no main-against-head numbers back the default yet. Flipping it mid-session is safe: blocks are interchangeable between the magazines and the global pool, and each node carriespooled.Reviewed:
428e6d1baagainst4908cc6da. Inhost/nvn_native.c, every changed hunk and the code it relies on (flatten,cmd_release,release_copies, the sweep,free_dead_copies,inline_recording,cmd_adopt's slot numbering). Alsogpu/vk/switches.defandtests/test_hos_ab.py. Intests/test_nvn_zerocopy_rec.py, its source checks and slicing, but not every line of its C harness. For comparison, the fibers inhost/hos_thread.cand the thread-end teardown inhost/nn_os_sync.c. A read-only merge against mainbe4942212. Nothing run.Fixed in this review: nothing.
Checked and fine:
copy_prefixat its head, andcopypoints past it, asflatten's result did.free_dead_copiesreturns the segment to its own class (pre->cls). A segment more than one class too large is flattened and returned instead, so a live copy holds no more memory than on main.cmd_reserve_rec) copies from after the prefix, andBeginRecordingstarts after it. With=0the copy is flattened from the same offset, andcmd_releasefrees whatever segment is left.cmd_next = 1), so the new!sdie incmd_adoptcan't fire.markedonly ever holds 0 or 1, souint8_tis enough.POOL_KEEP, and node slabs capped at 16 MiB.Blocking
host/nvn_native.c:1479(with 1422 and 1456-1458): the magazine is cached per OS thread (_Thread_local tls_pool_mag), but it is torn down through a fiber's FLS slot. Guest fibers are Win32 fibers (host/hos_thread.c:1823). They run on one thread after another, andFinalizeFiberdeletes one from whichever thread calls it (hos_thread.c:1834);DeleteFiberruns the FLS callback.pool_getorpool_putwhile running game fiber F, and F is later finalized from thread T2.pool_mag_drain_allthen runs on T2 and frees T1's magazine while T1'stls_pool_magstill points at it. T1's next recording writes into freed memory, and if T1 is insidepool_putat that moment the two threads race.tls_pool_mag_dead, and T1 runs without magazines for the rest of the session.POOL_KEEP.host/nn_os_sync.c:504-526describes this exact case for the object cache and handles it: a.CRT$XL*TLS callback onDLL_THREAD_DETACH, which runs per thread whatever fiber it is on, and a pthread key elsewhere. Do the same here and drop FLS.tests/test_obj_cache_size.pyhas a fiber case that the new test can copy.be4942212):host/nvn_native.c: main added(system/host-settings:nvn_rec_shift)to the comment above therec_nodetypedef that this PR moves. Keep main's comment and drop the typedef there.tests/test_hos_ab.py,WIRED: main droppedHOS_NATIVE_OCC_RASTERwhen the game side moved to Rust. Keep it dropped and add onlyHOS_NVN_ZEROCOPY_REC, in name order.Suggestions
tests/test_nvn_zerocopy_rec.py:34:assert nvn.count("hos_xmalloc(") == 3checks nothing this PR does, and it fails as soon as an unrelated allocation is added to the file. Drop it.host/nvn_native.c:1813(the predicted first segment): to avoid the doubling chain, predict from the largest of the last few sizes, or keep the segment when the prediction falls well short. Otherwise, measure a scene where it happens.HOS_NVN_ZEROCOPY_REC=checkrun with "0 mismatches". The switch is a bool and the diff adds no check mode, so that run compared nothing. Say in Testing what that run was.main" and "mise run testpasses", but the branch conflicts with main and the full suite wasn't run. Untick both until they hold.cmd_adoptchange (!s, the slot index computed inline) is outside this PR's topic. It is harmless but could go.Testing:
15b06ffe4and a 30 s run on428e6d1ba. The game-free checks named in the description and the comment passed; the fullrun_allwas not run.15b06ff: nvidia, amd and linux passed. windows+nvidia failed, with 2 PR runs crashed and a picture past the limit. intel couldn't be judged. The author reports that main crashed on the same testers, but the farm's summary lists only the PR's crashes, so a new run will settle it.@Beanstalk), CI on the head (every job still waits on its required conditions), RAM, and the fiber case.Overlaps and merge order:
HOS_NVN_REC_HANDOFF, hands a finished recording over instead of copying it) does the same handoff with another design.rec_nodelists) replaces what this PR's node pool pools.View command line instructions
Manual merge helper
Use this merge commit message when completing the merge manually.
Checkout
From your project repository, check out a new branch and test the changes.