digitalbazaar / cborld

A Javascript CBOR-LD processor for web browsers and Node.js apps.
https://json-ld.github.io/cbor-ld-spec/
BSD 3-Clause "New" or "Revised" License
18 stars 12 forks source link

Refactor to do encoding/decoding without re-encoding twice. #3

Closed msporny closed 3 years ago

msporny commented 4 years ago

The current code base was written to iterate on a number of intermediate formats to hone in on the final result. This means that there is an intermediate format that is used as a sort of abstract syntax tree which is then converted to the final form. This probably results in close to twice as much processing and even more memory usage than necessary. Once the final algorithm for v1.0 is settled on, we will want to refactor the code base so that the intermediate format is optimized out. I believe the current algorithm only makes one pass over the documents and thus there is no need to keep previous state around. We should be able to do stream processing (since stream processing is possible in JSON-LD and because I don't remember having to implement jumping around when processing contexts or encoding/decoding).

dlongley commented 3 years ago

Closing based on what's been implemented in PR #34. Full streaming support is not possible but it is more efficient now. A streaming format can be provided with a different compression mode in the future if desired.