Latest Results
refactor: trim output allocations and unify unknown-field sort (#96)
* refactor: trim output allocations and unify unknown-field sort
Stream output into a single byte buffer (BOM bytes prepended, serde_json
appends, one `from_utf8_unchecked` at the end) instead of building a
String, pushing '\n', and re-allocating to prepend the BOM. Saves a full
output-sized memcpy on BOM inputs and the post-serialize UTF-8 walk in
general.
Collapse `non_private` and `private` into a single `unknown` Vec sorted
by `(starts_with('_'), name)` — one allocation, one sort, and the
underscore check leaves the per-entry hot path.
Replace `sort_object_by_key_order`'s `obj.sort_keys()` + per-key
`shift_remove` (each shift moves the IndexMap tail) with a single-pass
classify into a slot Vec + remainder, then merge.
cargo bench (vs. main):
sort already sorted package.json: -6.06%
sort large package.json: -4.36%
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
* perf: pad output Vec capacity to absorb trailing newline
`Vec::with_capacity(input.len())` was sized to fit the JSON body
exactly when the input is already pretty-printed, so the trailing
`buf.push(b'\n')` would always trip a reallocation. For the minimal
benchmark (~77 byte input) this caused a measurable regression (CodSpeed
reported +13.83%) — `to_string_pretty` previously used serde's default
128-byte capacity, which had the headroom we lacked.
Pad the capacity by 16 bytes so the newline push never realloc's, while
still keeping the win for larger inputs where the hint avoids serde's
repeated 128 → 256 → 512 → … growth.
cargo bench (vs. main):
sort small package.json: -3.08%
sort already sorted package.json: -4.34%
sort minimal package.json: -1.35%
sort large package.json: -1.37%
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Opus 4.7 (1M context) <noreply@anthropic.com> Latest Branches
0%
0%
0%
release-plz-2026-05-08T12-07-16Z © 2026 CodSpeed Technology