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

Add spec for No-Vary-Search hint in speculation rules #278

Merged
merged 5 commits into from
Jul 4, 2023

Conversation

kjmcnee
Copy link
Collaborator

@kjmcnee kjmcnee commented Jun 14, 2023

We introduce the "expects_no_vary_search" field for speculation rules and specify how it is parsed.

When matching prefetch records, we now have it:

  • perform inexact matches based on the response's No-Vary-Search value
  • block on the availability of headers for potential matches
  • have the identification of potential matches incorporate the No-Vary-Search hint

Note that this spec text describes blocking on any available prefetch. The current chromium implementation blocks only on a single ongoing prefetch.

@github-actions
Copy link

@kjmcnee kjmcnee requested a review from jeremyroman June 14, 2023 18:10
no-vary-search.bs Outdated Show resolved Hide resolved
1. If |result| is null, then return null.
1. Otherwise return |result|.

<p class="note">Speculation rule parsing is strict, so the return value of this algorithm surfaces parsing errors instead of silently returning the [=default URL search variance=].
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm not sure that logic applies here. Here's my reasoning:

Whatever the meaning of the NVS header, recognized or unrecognized is, what we want to know is "would the prefetch cache, when it arrives, consider it to match?". In that light, I think it makes sense to match the behavior of the prefetch cache (and therefore, to treat this no more strictly than it does).

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Ah, I think I see your point. Also the motivation for the strictness described in "parse speculation rules" talks about misunderstood rules leading to more speculation than was intended. But here, we know the consequence of an invalid hint and it would not cause more speculation.

For debuggability, we should presumably still have the implementation warn about this.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Tagging @liviutinta in case of any concerns.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I've updated the parsing of the hint to fallback to the default variance. Note that in "parse a speculation rule" this still treats non-string values for expects_no_vary_search as invalid.

prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Outdated Show resolved Hide resolved
* |cutoffTime| is null or |record|'s [=prefetch record/creation time=] is less than |cutoffTime|.
1. If |potentialRecords| [=list/is empty=], return null.
1. Wait until the [=prefetch record/state=] of any element of |document|'s [=Document/prefetch records=] changes.
1. If |cutoffTime| is null and any element of |potentialRecords| has a [=prefetch record/state=] that is not "`ongoing`", set |cutoffTime| to the [=current high resolution time=] for the [=relevant global object=] of |document|.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Shouldn't this be set before the wait, possibly outside the loop? I assume the goal here is "don't block on prefetches which started after we first started looking"? The current semantics are, at least, confusing to me.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

The note below this explains the motivation. The goal is to allow prefetches started after we started blocking, which is why the cutoff isn't set until this point. Would it help to move the note next to this line?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Discussed a little aloud. I see the informative note below, but I'd appreciate it if it could be expanded to be explicit about the intuitive understanding of this heuristic (blocking only on prefetch requests which started before a prefetch completed), why we're using it (we want to allow a slightly later prefetch which is a better match, but don't want a fixed timeout that might cause issues with slow servers), and what its properties are (e.g., in the worst case, we block on two nearly-consecutive prefetches and then the actual navigation if we still failed to match).

Parentheticals are merely inspiration from my understanding and you can write a more cohesive note. :)

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Done.

prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Outdated Show resolved Hide resolved
prefetch.bs Show resolved Hide resolved
speculation-rules.bs Show resolved Hide resolved
@kjmcnee kjmcnee merged commit c1f4946 into WICG:main Jul 4, 2023
@kjmcnee kjmcnee deleted the nvs-hint-spec branch July 4, 2023 19:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants