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

Seek more clarity on Largest Reference/Base Index encoding #1403

Merged
merged 4 commits into from Jun 4, 2018

Conversation

martinthomson
Copy link
Member

I made some changes in #1363 to the explanation of how these are encoded because I found the explanation baffling. Here's that text, without the swap of the two values.

Now that I've read this 100 times, I think that it doesn't change anything material. It does have one change: making sign=1, delta=0 a decoder error. We could reclaim a bit by making the formula more complex, but that's a hard trade-off.

@martinthomson martinthomson added the editorial An issue that does not affect the design of the protocol; does not require consensus. label May 30, 2018
@martinthomson martinthomson requested a review from afrind May 30, 2018 02:54
Copy link
Contributor

@MikeBishop MikeBishop left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor stuff, except for where you obviously didn't type what you meant.


baseIndex = largestReference + deltaBaseIndex
To save space, Base Index is encoded as a relative to the Base Index using a
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

relative to Largest Reference

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, "encoded relative to" rather than "encoded as a relative to". Otherwise, I need to see how we encode second cousins.... 😉

is:

~~~
baseIndex = largestReference + sign * deltaBaseIndex
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While order of operations makes this correct, it might be worth parentheses for clarity.

baseIndex = largestReference + sign * deltaBaseIndex
~~~

If the encoder inserted entries to the table while the encoding the header
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know I wrote the previous iteration of this text, but this is baking in the assumption that Base Index was fixed before encoding began (i.e. single-pass encoding). Should that be called out?


A header block that does not reference the dynamic table can use any value for
Base Index and Largest Reference; sending zero values for both fields is the
most efficient.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can use any value for Base Index, and zero is the most efficient. I'd argue that zero for Largest Reference is probably a SHOULD, given that it has a defined meaning and isn't just used for relative indexing.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, I considered that, but it's not a SHOULD really, especially since we have defined Largest Reference already (it's the largest absolute index in the block). I'll adjust and let you decide if you want to merge.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Having no references and the value not being zero is a violation of what that field means. More generally, I think a decoder that wanted to have an error case for "You didn't actually reference the Largest Reference" would be well within its rights, and we might want to either mention that and define the error code or explicitly prohibit that.

Alan's doc, his call.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than bog this PR down, let's fix that separately.

@martinthomson martinthomson changed the title Seek more clarify on Largest Reference/Base Index encoding Seek more clarity on Largest Reference/Base Index encoding May 31, 2018
baseIndex = largestReference + (sign * deltaBaseIndex)
~~~

An encoder is expected to determine the absolute value of Base Index before
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A single-pass encoder

less than Base Index, so deltaBaseIndex will be positive and encoded with S=0.
When Largest Reference and Base Index are equal, deltaBaseIndex is 0 and encoded
with S=0.
That is, after turning a sign bit of 1 to -1 and 0 to 1, the absolute Base Index
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I find the language about turning a sign bit somewhat confusing.

Is it more clear to explain using a conditional?

if sign:
  baseIndex = largestReference - deltaBaseIndex
else:
  baseIndex = largestReference + deltaBaseIndex

Or index into an array?

signMultiplier = [ 1, -1 ]
baeIndex = largestReference + signMultipler[ sign ] * deltaBaseIndex

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, this is always hard to explain, but the conditional is nice. Verbose FTW.

An encoder is expected to determine the absolute value of Base Index before
encoding a header block. If the encoder inserted entries in the dynamic table
while encoding the header block, Largest Reference will be greater than Base
Index, so the encoded difference is negative and the sign bit will be 1. If the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: is vs. will be - can it be consistent?

baseIndex = largestReference + deltaBaseIndex
To save space, Base Index is encoded relative to Largest Reference using a
one-bit sign and the `Delta Base Index` value. A sign bit of 0 indicates that
the Base Index has a greater absolute index than the Largest Reference; the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

greater than or equal to, technically. We don't mention the zero case at all until the bottom.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Well the sentence says that the encoder added entries. I don't think that it's a problem to not mention the zero case.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this sentence says it added entries - are you referring to somewhere else? I think Mike's right here - if the Base Index is equal to LR then the sign bit will be 0. The original text had that, and it's included on lines 578-9 below. Is it clearer if we bring it back up here?

I agree we don't need to mention the case where they are both 0 here.

baseIndex = largestReference + deltaBaseIndex
To save space, Base Index is encoded relative to Largest Reference using a
one-bit sign and the `Delta Base Index` value. A sign bit of 0 indicates that
the Base Index has a greater absolute index than the Largest Reference; the
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where this sentence says it added entries - are you referring to somewhere else? I think Mike's right here - if the Base Index is equal to LR then the sign bit will be 0. The original text had that, and it's included on lines 578-9 below. Is it clearer if we bring it back up here?

I agree we don't need to mention the case where they are both 0 here.

the Base Index has a greater absolute index than the Largest Reference; the
value of Delta Base Index is added to the Largest Reference to determine the
absolute value of the Base Index. A sign bit of 1 indicates that the Base Index
is smaller than the Base Index. That is:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Base Index is smaller than the Largest Reference

@afrind afrind merged commit dd83b15 into master Jun 4, 2018
@MikeBishop MikeBishop deleted the explain-base-lr branch June 14, 2018 23:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
-qpack editorial An issue that does not affect the design of the protocol; does not require consensus.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants