Skip to content

[AUTOMATED] perf: reduce CLI cold startup overhead - #558

Merged
mahaloz merged 4 commits into
Noelo-Lab:mainfrom
TsingShui:perf/cli-cold-start
Sep 11, 2026
Merged

mahaloz merged 4 commits into
Noelo-Lab:mainfrom
TsingShui:perf/cli-cold-start

Conversation

@TsingShui

@TsingShui TsingShui commented Sep 11, 2026 •

Copy link
Copy Markdown
Contributor

What improves

A fresh CLI process spends less time loading the SLEIGH spec, and emits exactly
the same bytes. From the repository root:

decompiler/target/release/kuna decompile \
  decompiler/crates/kuna-analysis/tests/fixtures/fauxware main --json

Interleaved fresh-process pairs against the unpatched tree, output asserted
equal on every run:

command before after
decompile --json 152.6 ms 139.3 ms -8.7%, 59/60 pairs faster
decompile (text) 157.4 ms 143.7 ms -8.7%, 59/60
functions --json 148.1 ms 132.9 ms -10.2%, 56/60

(medians, Linux x86-64, warm filesystem cache; 80 pairs on macOS arm64 gave
84.8 -> 77.2 ms for the first row.) The saving is a fixed startup cost, so it is
the whole of a short command and invisible in a long one.

The change

  • An encoded integer that lies wholly inside the current chunk is read from that
    chunk's slice in one step instead of one call per byte. A read that reaches
    the chunk's end stays on the byte cursor, which is where end-of-stream is
    detected — no bounds or EOF check is skipped — and that cursor is now inlined.
  • FormatDecode hands the inflated buffer to PackedDecode instead of copying
    it into 1 KiB chunks; only the trailing partial chunk is copied, to carry the
    padding terminator. The chunk boundaries move; the ingested bytes, the NUL
    termination and the byte at which the stream ends do not.

Tests

New cases cover integers at every chunk edge, owned-vs-borrowed ingestion
equality, the leading chunk not being copied, truncated-integer errors, a
fast-path/byte-cursor cross-check, and SLA header, truncation, checksum and NUL
handling.

make test 675/675, make test-stages 776/776, make test-cli 127/127,
make test-ghidra, make rust-test (6500 passed, 0 failed), make check-spec
(strict) and kuna catalog --check all pass. decompile-all --json is
byte-identical — stdout, stderr and exit code — against 173 fixture binaries
spanning x86-64, i386, ARM, Thumb, ELF and PE.

🤖 Generated with Claude Code

https://claude.ai/code/session_01Y9qJyRdQu6vTqagaeSp4ef

TsingShui and others added 4 commits September 11, 2026 03:23
Avoid a function call per SLA byte while preserving chunk and EOF checks.
Fifty interleaved fresh-process runs on macOS arm64, with warm filesystem
cache and identical output: fauxware text 97.43 -> 89.28 ms, JSON
84.93 -> 78.40 ms, functions 82.83 -> 75.52 ms; Thumb JSON 52.62 -> 48.69 ms.

Datatests 675/675, stages 749/749, check-spec and catalog pass.
Release kuna-base tests: 194 passed. Full workspace: 6403 passed;
14 UPX-fixture tests fail because the host denies/removes the packed
witness. UPX is outside this change; its external deletion is not staged.

Co-authored-by: TRAE CLI <[email protected]>
…updates

Keep boundary-crossing and EOF reads on the checked byte path. Seventy
interleaved fresh-process runs against the preceding commit on macOS
arm64 (warm filesystem cache, identical output): fauxware text
90.65 -> 88.15 ms, JSON 79.18 -> 76.51 ms, functions 76.84 -> 74.48 ms;
Thumb JSON 49.32 -> 47.76 ms.

Datatests 675/675, stages 749/749, check-spec and catalog pass.
Release kuna-base: 195 passed. Full workspace: 6404 passed, with the
same 14 failures caused by the missing UPX witness; all other tests in
those three targets pass when only those fixture-dependent tests are
excluded. No UPX code, fixture, or expectation is changed.

Co-authored-by: TRAE CLI <[email protected]>
Transfer full packed chunks without copying or allocating each one;
copy only the partial tail to preserve NUL and EOF padding semantics.
Sixty interleaved fresh-process runs against the previous commit on
macOS arm64, warm filesystem cache: fauxware JSON 78.31 -> 74.77 ms,
functions 75.15 -> 71.94 ms, Thumb JSON 48.06 -> 46.20 ms. Output is exact.

Datatests 675/675, stages 749/749, check-spec and catalog pass.
Release base/SLEIGH tests: 504 passed. Workspace: 6410 passed and the
same 14 missing-UPX-fixture failures, outside the requested scope.
27 CLI success/error cases and 34875 valid/mutated/truncated packed
streams agree with the original path. No UPX changes are included.

Co-authored-by: TRAE CLI <[email protected]>
`ingest_owned` re-derived `end_ingest`'s pad byte and end position inline;
call `end_ingest` instead, so the padding contract keeps one definition and
the two ingest paths cannot drift.

The SLA/packed-decoder prose sat between the "0.1 The two tiers" heading and
its own first paragraph, and described an optimization rather than the
decoder. Move it beside the paragraph that resolves the specs tree and state
the invariants it rests on: chunk boundaries are not observable, the byte
extent and NUL termination are unchanged, and a boundary-reaching read stays
on the cursor that detects end-of-stream. Restore the C++
`FormatDecode::ingestStream` anchor the new doc comment dropped.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
Claude-Session: https://claude.ai/code/session_01Y9qJyRdQu6vTqagaeSp4ef
@mahaloz
mahaloz merged commit 86fe58f into Noelo-Lab:main Sep 11, 2026
2 checks passed
@TsingShui
TsingShui deleted the perf/cli-cold-start branch September 12, 2026 01:42
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.

2 participants