Implement a streaming API, and read input lazily
- Dominant language
- Rust
- Stars
- 118
- Forks
- 23
- PR merge metrics
- No merged PRs in 30d
Description
Depending on the formatter configuration, some nested levels will not be streamable, but for any layer that does not reorder its elements, that layer can be streamed.
In particular, the top level [`ParsedDocument`](https://github.com/google/json5format/blob/master/src/content.rs#L14) is represented as an outermost `Array`, most commonly consisting of `Object`-typed elements, which are typically not reordered.
In a fairly common scenario, some very large documents are large because they contain 100s or 1000s of top-level objects, but any individual object is more than likely of a much more manageable size. With streaming, we should be able to format each object as its parsed, which will be much better for large documents than the current implementation that requires reading the entire document into memory before formatting.
Only read from the input to the parser as needed (lazily) as the formatter completes formatting the previously streamed content. (This is sometimes referred to as "backpressure" provided by the formatter, to limit the flow of input from the parser.)
Contributor guide
Assessment
This issue has not been assessed yet.