Files
leleka/docs/architecture/size-fn.md
T

9.9 KiB

Function size pass (STRA-338, batch size-fn)

Every .rs file of the crates below was already within 400 lines (batches size-split-*). This batch brings the functions within the limits of limits.json (30 lines, complexity 10, nesting 4, 120 columns), longest first, with the behaviour unchanged: one helper per rule, stage or item kind, a small context struct for the values a long function threads through, builder and assert helpers for tests, big literals as constants. Entries of limits-allowlist.json of the fixed functions are gone.

Crates: strata-control, strata-desktop-core, leleka-deploy, leleka-gateway-text, leleka-gateway-domain, leleka-worker-protocol, leleka-runtime-client, leleka-offline-tools, leleka-gptoss, leleka-cpu-sys, leleka-cpu-kernels, leleka-cpu-worker, leleka-igpu*, leleka-gptoss-igpu, leleka-gptoss-npu, leleka-npu-*, leleka-gpu-npu-worker, leleka-gguf, leleka-kar-codec, leleka-harmony, leleka-tokenizer, leleka-shm, leleka-openvino, leleka-serving-policy, leleka-sampler-ref, leleka-quant-core, leleka-experimental-ref, leleka-native-parity-bench.

Numbers

  • Allowlist entries: 429 (all "moved verbatim ... not yet decomposed") -> 133 (115 older entries that remain, 18 new ones for the functions this pass touched and could not finish; the entries of the unfixed deploy tests are the largest group).
  • Functions over a limit in these crates, from the first line of the table: production fn>30 486 -> 17, complexity 340 -> 11, nesting 46 -> 0; test code fn>30 507 -> 122, complexity 35 -> 3, nesting 47 -> 4. Total functions listed by the census tool 1037 -> 144.
  • limits-baseline.json and architecture-baseline.json were regenerated with --update-baseline only (nothing raised).

Per crate (before -> after; production columns, then test columns; "wide" counts lines over 120 columns):

Crate prod fn>30 cx>10 nest>4 wide test fn>30 cx>10 nest>4 wide
leleka-cpu-kernels 1 -> 0 0 -> 0 0 -> 0 0 -> 0 8 -> 6 3 -> 1 5 -> 3 1 -> 1
leleka-cpu-sys 11 -> 0 3 -> 0 2 -> 0 3 -> 3 16 -> 16 0 -> 0 0 -> 0 2 -> 2
leleka-cpu-worker 7 -> 0 5 -> 0 0 -> 0 6 -> 5 6 -> 0 1 -> 0 2 -> 0 11 -> 5
leleka-deploy 101 -> 0 48 -> 0 7 -> 0 305 -> 247 89 -> 64 0 -> 0 0 -> 0 63 -> 60
leleka-experimental-ref 15 -> 0 11 -> 0 1 -> 0 19 -> 4 14 -> 9 2 -> 1 2 -> 1 37 -> 37
leleka-gateway-domain 15 -> 0 12 -> 0 5 -> 0 45 -> 16 3 -> 0 0 -> 0 0 -> 0 1 -> 1
leleka-gateway-text 14 -> 0 16 -> 0 1 -> 0 64 -> 61 12 -> 0 0 -> 0 2 -> 0 20 -> 6
leleka-gguf 6 -> 0 6 -> 0 0 -> 0 3 -> 1 3 -> 0 0 -> 0 0 -> 0 1 -> 1
leleka-gptoss 12 -> 0 6 -> 0 1 -> 0 1 -> 1 14 -> 5 4 -> 0 0 -> 0 8 -> 7
leleka-gptoss-igpu 1 -> 0 1 -> 0 0 -> 0 2 -> 2 5 -> 1 0 -> 0 0 -> 0 3 -> 3
leleka-gptoss-npu 5 -> 0 3 -> 0 2 -> 0 3 -> 2 4 -> 1 0 -> 0 0 -> 0 6 -> 5
leleka-gpu-npu-worker 3 -> 0 1 -> 0 0 -> 0 3 -> 2 2 -> 0 1 -> 0 0 -> 0 4 -> 1
leleka-harmony 4 -> 0 6 -> 0 2 -> 0 1 -> 0 3 -> 0 0 -> 0 0 -> 0 5 -> 0
leleka-igpu 10 -> 1 1 -> 0 0 -> 0 5 -> 5 12 -> 12 1 -> 1 0 -> 0 0 -> 0
leleka-igpu-worker 2 -> 0 1 -> 0 0 -> 0 1 -> 1 0 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-kar-codec 4 -> 0 3 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-native-parity-bench 0 -> 0 0 -> 0 0 -> 0 9 -> 9 0 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-npu-service 6 -> 0 5 -> 0 0 -> 0 14 -> 3 3 -> 0 0 -> 0 1 -> 0 1 -> 1
leleka-npu-worker 2 -> 0 1 -> 0 0 -> 0 2 -> 2 2 -> 2 0 -> 0 0 -> 0 0 -> 0
leleka-offline-tools 8 -> 0 5 -> 0 0 -> 0 1 -> 0 3 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-openvino 2 -> 1 0 -> 0 0 -> 0 1 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-quant-core 1 -> 0 0 -> 0 2 -> 0 0 -> 0 11 -> 0 1 -> 0 0 -> 0 0 -> 0
leleka-runtime-client 9 -> 0 4 -> 0 0 -> 0 4 -> 3 6 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-sampler-ref 9 -> 0 4 -> 0 0 -> 0 0 -> 0 14 -> 0 1 -> 0 2 -> 0 0 -> 0
leleka-serving-policy 13 -> 0 10 -> 0 0 -> 0 6 -> 5 9 -> 0 0 -> 0 0 -> 0 1 -> 1
leleka-shm 1 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0 0 -> 0
leleka-tokenizer 13 -> 0 7 -> 0 0 -> 0 21 -> 14 10 -> 0 1 -> 0 0 -> 0 10 -> 2
leleka-worker-protocol 3 -> 0 3 -> 0 0 -> 0 0 -> 0 1 -> 0 0 -> 0 0 -> 0 0 -> 0
strata-control 146 -> 0 122 -> 0 17 -> 0 185 -> 50 194 -> 0 17 -> 0 30 -> 0 131 -> 17
strata-desktop-core 62 -> 15 56 -> 11 6 -> 0 52 -> 13 63 -> 6 3 -> 0 3 -> 0 27 -> 0
total 486 -> 17 340 -> 11 46 -> 0 756 -> 449 507 -> 122 35 -> 3 47 -> 4 332 -> 150

What stays over a limit, and why

  • igpu/src/shaders/gemm.rs :: gemm (175 lines): WGSL shader text returned as one string; data, not logic.
  • openvino/src/library.rs :: OpenVino::load (84): FFI symbol table of about 25 dlsym lookups; the table is the point.
  • strata-desktop-core (15 production functions: ToolResponse::complete/preflight, hardware::inventory, node_proxy::respond, node_connection::session, Agent::respond, planner::plan, Pool::new, managed_worker start/run/Owner::command, cli::node::serve/parse_mode, main/file_command, evaluation_measurement, and a few within 1 to 4 lines of the limit): time box. They carry allowlist entries (owner STRA-338) and are the first items of the next batch.
  • leleka-deploy tests (64 functions, all over 30 lines, none over complexity 10; mostly e2e_windows, recipe, the planner tests and unit tests in src/*/tests*) and the tests/examples of cpu-sys, cpu-kernels, igpu, experimental-ref, gptoss, npu-worker: time box.
  • Wide lines: 449 production lines and 150 test lines remain over 120 columns, mostly long messages and the JSON literals of fake runtimes; rustfmt cannot wrap them and the text must stay byte-identical.

Kernels

The owner allowed the hot numeric kernels to be split. Rule used: helpers keep the arithmetic order (no reassociation, no change of FMA or accumulation order), keep the unsafe blocks and SAFETY comments with their code, and are #[inline(always)] where the original was one body in a hot loop (#[inline] with the same #[target_feature] for AVX2 and AVX-VNNI helpers, because inline(always) cannot be combined with target_feature). Tensor identity was proven per function with a throwaway test that compiled the original files from git next to the new ones and compared output bits on fixed xorshift inputs:

Crate Functions Proof
leleka-cpu-sys simd x86 attn_weighted_sum_avx2, attn_weighted_sum_f16_avx2, dot_i8i8_avxvnni, dot_i4i8_avxvnni, dot_mxfp4_q8r4_avxvnni, dot_mxfp4_q8r4_avx2, quantize_q8_0_avx2 792 cases bit-identical in debug and release (attention heads 1-4, hd 1-192, n 1-40; dots n 0-513; mxfp4 0-33 blocks; quantize 0-33 blocks incl. zero and -0.0). The host CPU has no AVX-VNNI: the three VNNI variants were compared with vpdpbusd replaced by a scalar emulation (proves the restructuring, not the instruction), and the real VNNI path was only compiled
leleka-cpu-kernels Dispatch::with_isa (three tables moved unchanged) existing parity tests
leleka-quant-core iq3_s::decode_block, iq3_xxs::decode_block 40000 random blocks per format bit-identical (iq3_s also 845 identical error texts)
leleka-gptoss attend_group_with_sink, kar_roundtrip 6 shapes x ISA levels (12 cases) and 46 round-trip cases, outputs and error paths identical

No performance claim is made. The codegen effect of the splits is not A/B-measured; the kernels on the serving path need a paired A/B (same workload, quality result) before anything is said about speed.

Verification

  • Test ids and outcomes: cargo test --no-fail-fast --all-targets on Linux (WSL) for the 28 crates and for `leleka-deploy
    --features test-fakes, before (0c594d351) and after, compared with scripts/dev/test-outcomes.py compare`
    0 missing, 0 new, 0 outcome changes (strata-control and the 27 other crates: 1067 ok before, 1078 ok after, the 11 differences are tests that the base log could not resolve or that failed once on the base; leleka-deploy: 213 ok / 5 failed / 2 ignored before and after). The five leleka-deploy e2e failures (dry_run_prints_the_plan_and_changes_nothing and four in reconfigure_flow) fail on the base too: they report the free VRAM of the host GPU. The strata-control lib suite had one flaky failure on the base run (responses::tests::history::durable_history_roundtrip_delete_eviction_and_faults).
  • cargo clippy --no-deps --all-targets -- -D warnings clean for the crates above; result_large_err is allowed in the modules of the /v1/responses handler and the gateway relay of strata-desktop-core because the error value is the finished HTTP response. cargo fmt --check for strata-control, strata-desktop-core, leleka-runtime-client and leleka-deploy differs only in files this batch did not change.
  • Gates: scripts/check-limits.py --base origin/claude/hexagonal-integ 0 errors, 0 stale; scripts/check-architecture.py 0 errors (the dyn-trait ratchet of strata-desktop-core is held by spelling dyn leleka_backend_api::Backend in the binaries); scripts/check-ci-coverage.py green.

Method note

The work was split by directory over parallel branches (claude/szfn-*), each in its own worktree with its own target directory, then merged here. Functions were fixed longest first; helpers are placed in new sibling modules where a file would pass 400 lines. New modules are listed in the commits.