Skip to content

Matcha 0.1.2 — 9x Encode / 4x Decode Performance

Latest

Choose a tag to compare

@christopherkarani christopherkarani released this 09 Apr 04:08

Performance

Major performance optimization targeting Swarm-style artifact workloads.

Benchmark Results (release mode, 500 loops)

Artifact Encode Speedup Decode Speedup
WebSearchEvidenceRecord 7.2x faster 3.6x faster
EvidenceBundleRecord 5.8x faster 3.4x faster
WebSearchEnvelope 9.4x faster 4.1x faster

Matcha encode is now within 1.6x of JSON encode speed while maintaining 4–9% smaller output.

What Changed

  • Native Codable Encoder — Encodable types now convert directly to MatchaValue, eliminating the JSONEncoder → JSON string → parseJSON roundtrip (3 intermediate passes removed)
  • Native Codable Decoder — MatchaValue now decodes directly to Decodable types, eliminating the toJSONObject → JSONSerialization → JSONDecoder roundtrip (3 intermediate passes removed)
  • Single-pass string escaping — escapeString() reduced from 5 sequential string scans to 1 UTF-8 pass
  • Single-pass safety checks — isSafeUnquoted() reduced from 10+ sequential contains() calls to 1 UTF-8 pass
  • UTF-8 byte scanning — Eliminated Array(string) Character allocations in 6 hot-path parser functions
  • Fast ASCII whitespace trim — Replaced Foundation trimmingCharacters(in:) with lightweight inline trim

Compatibility

  • All 25 tests pass (22 existing + 3 new Codable round-trip tests)
  • Serialization format unchanged — output is byte-identical
  • Compactness advantage preserved (4–9% smaller than JSON)
  • No public API changes