fix(cbor): eliminate dead WithLength decoder family#220
Open
Mechack08 wants to merge 1 commit intoIntersectMBO:mainfrom
Open
fix(cbor): eliminate dead WithLength decoder family#220Mechack08 wants to merge 1 commit intoIntersectMBO:mainfrom
Mechack08 wants to merge 1 commit intoIntersectMBO:mainfrom
Conversation
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
8d40dbf to
294ee9f
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Removes the entire
WithLengthslice-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 integeroffsetthrough every call, zero allocation, zero buffer copies.WithLength-family (decodeItemWithLengthSync,decodeBytesWithLengthSync,decodeArrayWithLengthSync, …) — callsdata.slice(offset)at every recursive level, allocating a newUint8Arrayper nested CBOR item. O(n²) allocation for deeply nested PlutusData.What was found
Through static analysis, the
WithLengthfamily was confirmed to be completely dead code:The live decode path has always been:
What changed
Deleted the following functions from CBOR.ts:
decodeUintSyncdecodeNintSyncdecodeBytesWithLengthSyncdecodeTextWithLengthSyncdecodeItemWithLengthSyncdecodeArrayWithLengthSyncdecodeMapWithLengthSyncdecodeTagWithLengthSyncdecodeSimpleOrFloatSyncdecodeLengthSyncNet: −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.