Skip to content

refactor(core): migrate lang_analyzer cache from bincode to postcard#16

Merged
inureyes merged 2 commits into
mainfrom
refactor/issue-8-migrate-bincode-to-postcard
May 18, 2026
Merged

refactor(core): migrate lang_analyzer cache from bincode to postcard#16
inureyes merged 2 commits into
mainfrom
refactor/issue-8-migrate-bincode-to-postcard

Conversation

@inureyes
Copy link
Copy Markdown
Member

Summary

  • Replace bincode 1.x (RUSTSEC-2025-0141, permanently unmaintained) with postcard 1.x in mlxcel-core's lang_analyzer disk cache
  • Remove the corresponding [advisories.ignore] entry from deny.toml now that bincode is gone from the dep tree

Architectural decision

postcard 1.x was chosen over the other alternatives (bitcode, rkyv, bincode 2.x) for these reasons:

  • 1.0+ stable with frozen wire format: production users' on-disk caches are safe across future dependency upgrades; bitcode is pre-1.0 and has changed wire formats between minor versions
  • Drop-in serde API: postcard::to_allocvec(&v)? / postcard::from_bytes::<T>(&bytes)? — minimal change to the 3 call sites in one file
  • Embedded ecosystem standard: natural fit for an inference runtime crate; actively maintained
  • Use case is not performance-critical (one startup read, KB-scale cache file), so bitcode's speed/size advantages do not apply here

Cache format compatibility

mlxcel-core's corrupt-detection path in lang_analyzer/cache.rs renames any file that fails deserialization to *.broken.<epoch>.bak before rebuilding from the tokenizer source. Production users with old bincode-format caches will gracefully degrade on upgrade — the postcard from_bytes call will fail, the corrupt-detection path fires, and the cache is rebuilt automatically. No explicit migration code is needed.

What changed

  • src/lib/mlxcel-core/Cargo.toml: bincode = "1"postcard = { version = "1", features = ["alloc"] }
  • src/lib/mlxcel-core/src/lang_analyzer/cache.rs: bincode::deserializepostcard::from_bytes, bincode::serializepostcard::to_allocvec, doc comments updated
  • src/lib/mlxcel-core/src/lang_analyzer/mod.rs: Bincode(#[from] bincode::Error)Postcard(#[from] postcard::Error), module doc updated
  • deny.toml: removed RUSTSEC-2025-0141 ignore entry; paste entry retained

Verification

  • cargo check --lib -p mlxcel-core --no-default-features — passes cleanly
  • cargo tree -p mlxcel-core -i bincode — returns "package not found" (bincode fully removed)
  • cargo deny check — passes with advisories ok and RUSTSEC-2025-0141 no longer ignored

Closes #8

inureyes added 2 commits May 18, 2026 17:48
Replace bincode 1.x (RUSTSEC-2025-0141 — permanently unmaintained) with postcard 1.x in the three call sites inside mlxcel-core's lang_analyzer/cache.rs. postcard 1.x is 1.0+ stable with a frozen wire format, serde-based (drop-in API), and is the embedded Rust ecosystem standard — a natural fit for an inference runtime crate.

Changed files: Cargo.toml (bincode → postcard 1 alloc feature), cache.rs (bincode::deserialize → postcard::from_bytes, bincode::serialize → postcard::to_allocvec, doc comments updated), mod.rs (Bincode error variant → Postcard, module doc updated).
bincode 1.x is no longer in the dependency tree (replaced by postcard 1.x in mlxcel-core). Remove the ignore entry so cargo deny enforces the advisory going forward. The paste advisory (RUSTSEC-2024-0436) is retained — it is a separate transitive-via-tokenizers concern, unchanged by this PR.
@inureyes inureyes added status:review Under review type:refactor Code restructuring without changing functionality priority:medium Medium priority area:core mlxcel-core: MLX FFI, primitives, KV cache, layers labels May 18, 2026
@inureyes inureyes merged commit a84284e into main May 18, 2026
3 of 4 checks passed
@inureyes inureyes deleted the refactor/issue-8-migrate-bincode-to-postcard branch May 18, 2026 08:49
@inureyes inureyes self-assigned this May 18, 2026
@inureyes inureyes added status:done Completed and removed status:review Under review labels May 18, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:core mlxcel-core: MLX FFI, primitives, KV cache, layers priority:medium Medium priority status:done Completed type:refactor Code restructuring without changing functionality

Projects

None yet

Development

Successfully merging this pull request may close these issues.

refactor: migrate mlxcel-core off unmaintained bincode 1.x

1 participant