endo icon indicating copy to clipboard operation
endo copied to clipboard

For performance, compactOrdered decodePassable should minimize reparsing

Open gibson042 opened this issue 2 years ago • 1 comments

Extracted from https://github.com/endojs/endo/pull/1594#discussion_r1285296392

What is the Problem Being Solved?

The depth-aware array-decoding function introduced in #1594 is aware of each leaf node in a deep structure, but decoding is a recursive operation with string input. This means that nested arrays are fully traversed and comprehended, but that information is discarded in the calls that ultimately deserialize their constituent elements.

Description of the Design

The function should instead be provided with an ephemeral cache shared across the call stack of an outermost call to decodePassable, such that the outermost decodeArray function can populate it and reentrant calls can return from it rather than iterating over an already-visited slice of the input string.

Security Considerations

None in particular.

Scaling Considerations

This is only worth pursuing if it actually improves performance, specifically time complexity without an undue degradation of space complexity.

Test Plan

Per the above, we should perform some kind of benchmarking.

Upgrade Considerations

None; this will be a functionality-preserving optimization.

gibson042 avatar Aug 28 '23 21:08 gibson042

@gibson042 , does this also apply to compactOrdered? If not, I suggest closing as won't fix. If so, I suggest renaming.

erights avatar Mar 04 '24 18:03 erights