Skip to content

fix(cbor): eliminate dead WithLength decoder family#220

Open
Mechack08 wants to merge 1 commit intoIntersectMBO:mainfrom
Mechack08:fix/eliminate-with-length-decoder-family
Open

fix(cbor): eliminate dead WithLength decoder family#220
Mechack08 wants to merge 1 commit intoIntersectMBO:mainfrom
Mechack08:fix/eliminate-with-length-decoder-family

Conversation

@Mechack08
Copy link

Summary

Removes the entire WithLength slice-based decoder family from CBOR.ts (~369 lines of dead code), resolving [#159].

Background

CBOR.ts contained two complete decoder implementations side by side:

  • At-family (decodeItemAt, decodeBytesAt, decodeArrayAt, …) — threads an integer offset through every call, zero allocation, zero buffer copies.
  • WithLength-family (decodeItemWithLengthSync, decodeBytesWithLengthSync, decodeArrayWithLengthSync, …) — calls data.slice(offset) at every recursive level, allocating a new Uint8Array per nested CBOR item. O(n²) allocation for deeply nested PlutusData.

What was found

Through static analysis, the WithLength family was confirmed to be completely dead code:

  • No public API function calls it
  • No exported symbol references it
  • No external file calls it
  • Its only callers are itself (pure internal recursion)

The live decode path has always been:

fromCBORBytes / fromCBORHex
  → internalDecodeSync
    → decodeItemAt   ← At-family only

What changed

Deleted the following functions from CBOR.ts:

  • decodeUintSync
  • decodeNintSync
  • decodeBytesWithLengthSync
  • decodeTextWithLengthSync
  • decodeItemWithLengthSync
  • decodeArrayWithLengthSync
  • decodeMapWithLengthSync
  • decodeTagWithLengthSync
  • decodeSimpleOrFloatSync
  • decodeLengthSync

Net: −369 lines, no logic changes.

Testing

All 973 tests pass with no changes required — confirming the deleted code was never on any live execution path.

Test Files  62 passed (62)
     Tests  973 passed | 6 skipped (979)

The WithLength slice-based decoder family (decodeItemWithLengthSync,
decodeBytesWithLengthSync, decodeArrayWithLengthSync,
decodeMapWithLengthSync, decodeTagWithLengthSync, decodeTextWithLengthSync,
decodeUintSync, decodeNintSync, decodeSimpleOrFloatSync, decodeLengthSync)
was never called from any live code path and was never exported.

The actual decode path was always:
  fromCBORBytes / fromCBORHex -> internalDecodeSync -> decodeItemAt (At-family)

The WithLength family called data.slice(offset) at every recursive level,
allocating a new Uint8Array per nested CBOR item - O(n^2) allocation for
deeply nested PlutusData. The At-family threads an integer offset with
zero allocation.

Deleted ~369 lines of dead code. All 973 tests pass.

Closes IntersectMBO#159
@Mechack08 Mechack08 force-pushed the fix/eliminate-with-length-decoder-family branch from 8d40dbf to 294ee9f Compare March 22, 2026 09:32
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.

1 participant