perf: decode rewrite, encode zeros optimization, iai-callgrind benchmarks (0.3.1)

Decode rewritten with shrinking-slice pattern (split_first/split_at)
instead of index arithmetic. Decode zeros 14% faster, decode nonzero
flips from 5% behind corncobs to 2% ahead, decode mixed closes to tied.

Encode zeros fast path moved before split_at — now tied with cobs
(was 6% behind). Code size reduced to 821B (was 869B).

Replaced criterion with iai-callgrind for deterministic instruction-count
benchmarks via Valgrind. Zero run-to-run variance. Expanded to 162
benchmarks across 9 sizes.

ucobs now wins or ties 16 of 18 benchmarks vs corncobs and cobs.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
swaitsandClaude Opus 4.6 committed 2026-03-31 21:43:06 -06:00
1 parent ff883d6f8e
commit 777a37d4cd
9 files changed
+420 -217

No files matched your search

+20 -4
View File
@@ -4,8 +4,8 @@
default:
@just --list
# run ALL quality gates (tests, clippy, fmt check, doc, fuzz, miri)
test: test-unit test-clippy test-fmt test-doc test-fuzz test-miri
# run ALL quality gates (tests, clippy, fmt check, doc, fuzz, miri, mutants)
test: test-unit test-clippy test-fmt test-doc test-fuzz test-miri test-mutants
# quick compile check (no tests)
check:
@@ -39,10 +39,26 @@ test-fuzz:
test-miri:
cargo +nightly miri test -- --skip proptests
# run criterion benchmarks (ucobs vs cobs vs corncobs)
bench:
# mutation testing (requires cargo-mutants)
test-mutants:
cargo mutants --no-shuffle
# run iai-callgrind benchmarks (deterministic instruction counts, requires valgrind)
bench: bench-iai bench-size
# run iai-callgrind benchmarks (ucobs vs cobs vs corncobs)
bench-iai:
cargo bench
# measure compiled code size (encode + decode .text bytes)
bench-size:
@cargo build --release 2>/dev/null
@echo ""
@echo "Code size (release, encode + decode .text):"
@nm -S target/release/libucobs.rlib 2>/dev/null \
| grep 'T _ZN5ucobs' \
| awk '{size=strtonum("0x"$2); name=$4; sub(/.*ucobs[0-9]*/, "", name); sub(/17h.*/, "", name); printf " ucobs %-7s %4d B\n", name, size}'
# run python cobs benchmarks (requires: pip install cobs)
bench-python:
python3 bench_python.py