Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Structured responses section for streaming loading #212

Closed
nyaxt opened this issue Jun 13, 2018 · 0 comments
Closed

Structured responses section for streaming loading #212

nyaxt opened this issue Jun 13, 2018 · 0 comments

Comments

@nyaxt
Copy link
Collaborator

nyaxt commented Jun 13, 2018

Goal

  • Easier streaming consumption of large bundles.
  • Easier non-streaming consumption of the small bundles.

Background

In the current bundle spec, the structure of the responses section is allowed to be very flexible and not required to be a CBOR construct.

Streaming loading algorithm for current format

When loading a bundle in a streamed fashion, currently the parser will:

  1. Consume the index section
  2. Sort the exchanges by their response range offset
  3. Consume the other sections up till the responses section
  4. Discard the bytes until it reaches the first exchange in the sorted list
  5. Buffer the bytes until it reaches the end of the the first exchange
  6. The first exchange becomes ready for its use:
  7. Parse its responses header CBOR map
  8. Read its payload
  9. Append bytes to the buffer until it reaches the end of the next item.
  10. The second exchange becomes ready for its use.
  11. ...

Since there may be overlap in the response exchange, we need to keep around the original responses section in the buffer (which probably will reside on memory), since they may theoretically be used more than 1 time in a different CBOR interpretation. It is non-trivial to compute the "done" part of the responses section which are not referenced in later exchanges to partially free the original responses bytes buffer.

Non-streaming consumption of the small bundles

If the entire bundle is guaranteed to be a valid CBOR, it will become very easy to consume small packages which will easily fit in memory. If efficiency is not an issue, you can feed the entire package to CBOR parser, and consume the exchanges without implementing the full parsing algorithm.

For example, @irori created a live web demo of unbundler which assumes that the bundler output a CBOR array as response section.

Proposals

  • Specify the structure of the responses section
    • A valid CBOR array?
  • An index section entry references the response via array index, not offset
    • Enforces the start of the response is aligned to the start of the item in the responses CBOR array
    • Can save an alignment assert in the parser
  • Require the responses section to be always after the index section
jyasskin added a commit to jyasskin/webpackage that referenced this issue Jun 20, 2018
…order.

This lets us store only lengths in the index, and compute offsets from
them, which in turn enforces that the contents don't overlap and don't
have gaps, making the content array well-formed CBOR.

This applies to both the section index and the request index.

Fixes WICG#212.
jyasskin added a commit to jyasskin/webpackage that referenced this issue Jun 20, 2018
…order.

This lets us store only lengths in the index, and compute offsets from
them, which in turn enforces that the contents don't overlap and don't
have gaps, making the content array well-formed CBOR.

This applies to both the section index and the request index.

Fixes WICG#212.
jyasskin added a commit to jyasskin/webpackage that referenced this issue Jun 22, 2018
…order.

This lets us store only lengths in the index, and compute offsets from
them, which in turn enforces that the contents don't overlap and don't
have gaps, making the content array well-formed CBOR.

This applies to both the section index and the request index.

Fixes WICG#212.
jyasskin added a commit that referenced this issue Jun 22, 2018
…order. (#226)

This lets us store only lengths in the index, and compute offsets from
them, which in turn enforces that the contents don't overlap and don't
have gaps, making the content array well-formed CBOR.

This applies to both the section index and the request index.

Fixes #212.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant