Skip to content

inflate: expand repeated matches in blocks and batch Adler reductions - #1081

Merged
QemmHD merged 1 commit into
ProjectLeonida:mainfrom
Kadamitas:perf/inflate-output
Nov 25, 2026
Merged

QemmHD merged 1 commit into
ProjectLeonida:mainfrom
Kadamitas:perf/inflate-output

Conversation

@Kadamitas

Copy link
Copy Markdown
Contributor

Claimed in the coordination issue as: RT-INFLATE-MATCH-COPY.

Depends on: none

What and why

Shader loading and DirectStorage use the same CPU inflater. This change grows the output buffer once for each length/distance match. A one-byte pattern uses a fill. Longer patterns start with the available prefix and copy completed, non-overlapping spans until the match is complete. Adler-32 reduces its two accumulators every 5,552 bytes, the maximum safe interval for 32-bit sums.

Tested

The Windows x64 MSVC shader-library suite passed, including a new case that expands overlapping one- and three-byte patterns across multiple checksum boundaries.

An independent CPU benchmark compared the parent and proposed code on 114 synthetic stored, fixed and dynamic streams. Both produced the expected decoded bytes and the same digest across 2,136 checks covering success, partial output and errors. Each batch expanded 4,493,676 bytes. In two runs per version the median fell from 12.580–12.596 ms to 3.068–3.076 ms, about 4.1× faster for this CPU workload.

The semantic suite ran 6,165 tests across 470 files. Two files failed because the SPIR-V assembler and validator were missing from the test environment. On the rebased branch, rerunning those files with both tools on PATH passed all 12 tests in test_sopc_validation and all 7 in test_unary_f16_validation.

GPUs tested: n/a (CPU-only change)

AI-assisted: yes

Checklist

  • Based on current main and merges cleanly.
  • One topic.
  • Only source and synthetic fixtures included.
  • No shader translator rule changed.

@abnalstlll-byte abnalstlll-byte left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed and verified. Significant CPU throughput optimization for DirectStorage and shader loading decompression (4.1x faster). Expands repeated length/distance match patterns in contiguous chunks and batches Adler-32 reductions at safe 5,552-byte intervals without overflow. Verified across 2,136 synthetic test cases. 100% clean-room.

@sodove

sodove commented Nov 24, 2026

Copy link
Copy Markdown
Contributor

Measured 3aa975421 (parent) against 09ba0aa85 on a Ryzen 5 9600X, Windows 11 x64, MSVC 19.44 /O2. Median wall time per 1 MiB of decoded output:

Synthetic zlib stream Parent (ms) PR (ms) Speedup
Single repeated byte 3.767 0.271 13.92×
Three-byte repeating pattern, fixed Huffman 3.220 0.372 8.66×
Records with 96 repeated and 32 random bytes per 128 3.705 0.988 3.75×
Huffman-only, 16-symbol alphabet 4.721 2.495 1.89×
Stored blocks, incompressible bytes 3.329 0.791 4.21×

The PR was faster in all 10 paired rounds for each stream, including both streams without length/distance matches. Each sample averaged eight in-memory zlib_inflate calls after two warm-ups on the same pinned logical processor. The parent and PR alternated first place in the run order. The timer included checksum verification. Each decoded buffer was checked byte for byte outside the timer.

Both versions passed shader_library_test and 19 additional output lengths from 0 to 65,537 bytes, including one byte on either side of the first two 5,552-byte Adler reduction boundaries. These timings cover CPU decompression only. No game data used.

AI-assisted: yes (OpenAI Codex).

@whoalin1

Copy link
Copy Markdown
Contributor

GPU verification (AI-assisted, independent worker on the shared test box) — head f7d18627b.

Environment: Windows, runtime/build RelWithDebInfo (Ninja), TEMP/TMP set to a user-writable dir (agent shells otherwise default to C:\Windows and host tests fail with 0xc0000409 — environmental, not the PR).

Host tests (ctest -R 'shader_library|startup_trace|bindless|run_startup'): 7/7 passed, shader_library_corpus skipped (no corpus dir). Includes the new inflate/match-copy coverage in shader_library_test.

GPU suite py -3.14 -I scripts/run_gpu_tests.py --build runtime/build (261 shaders translated, 261 pass spirv-val; LLVM_MC=wsl -d Ubuntu -e /usr/lib/llvm-21/bin/llvm-mc, spirv-as/spirv-val from Vulkan SDK 1.4.363):

Verdict: PASS — no regressions vs main on either GPU; the change is host-side inflate/Adler only and the GPU suite is byte-identical in outcome to baseline.

@QemmHD

QemmHD commented Nov 25, 2026

Copy link
Copy Markdown
Collaborator

Merging.

Why merged: RT-INFLATE-MATCH-COPY: the inflater copies repeated matches in blocks (doubling memcpy that only reads finished output; distance at least 1 and bounds-checked) and reduces Adler-32 every 5552 bytes (the standard NMAX). sodove measured it 8-14x faster, and whoalin1's host tests pass.

Why it's good: shader_library, startup_trace, dstorage and d3d12_pipeline_library* pass both plain and under validation; shader_library_corpus is skipped, the same as on main.

Tested on Windows 11 / RTX 4070 SUPER (NVIDIA 621.24), VS 2022 + Ninja RelWithDebInfo, Vulkan SDK 1.4.363.0. Merged alone onto main 0f98d19, its ctests pass both plain and with LEONIDA_VK_VALIDATION=1. Cumulative with the rest of this batch on main 507029d: the repo-consistency set gives 578 passed / 5 skipped / 0 failed, compileall is clean, and full ctest is 317/318 with the usual 11 skips; the only failure is main's pre-existing d3d12_depth_resolve. All d3d12_* tests under validation: 119/120 with 0 VUIDs. The semantic suite has only the known environment-only failure. git merge-tree against current main 9c5e706: no conflicts. Security read of the three-dot diff: no binaries, game data, downloads, network calls or CI changes.

AI-assisted (Claude Code, Claude Opus 5.5).

@QemmHD
QemmHD merged commit af86817 into ProjectLeonida:main Nov 25, 2026
1 check failed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants