-
Notifications
You must be signed in to change notification settings - Fork 336
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
Can headers ordering be lessened? #189
Comments
Well, I think whatever we do the order needs to be defined since it is observable. Or defined to be random, but that seems suboptimal. Curious to hear what others think with respect to requiring a more efficient order. |
@youennf, do you have a use case where the optimization of this data structure has a measurable impact? |
No real use case on my side, although the fetch algorithm often uses headers get(), which is an indication that it should be made fast enough by browsers. WebKit already has a headers structure that does not preserve insertion order. Lexicographical ordering would solve this although this may hinder some other cases? |
The vast majority of Headers objects will have ~10 headers or less. Simple lists are typically faster for those numbers of items than hash tables, etc. The overhead of the heavier data structure outweighs any benefit from the better algorithmic complexity. I defer to @annevk about dropping a content exposed behavior like strict ordering, but it does not seem worth making a change here to me. |
Some additional points:
Overall, I agree this is not a big issue. |
Thinking about it some more, I don't understand how this hash table alternative deals with duplicates that cannot be combined, e.g., |
Currently it cannot and this needs to be fixed. |
That would make it even more complicated compared to the current list. You would have a hash table of name : values mappings and then an individual value would have some flag to indicate it needs to be serialized as its own header. The current design might not be so bad, all things considered. |
If container is an array, I guess the only needed thing would be to sort it when JS iteration is needed. As mentioned in WebKit entry, doing a set is different from doing a remove-then-append operation, which seems a bit strange. That said, after some WebKit internal discussions, we seem to be heading towards using a list container. |
The way the While this is a little strange, it provides a simple map-based API for the common case, but if you need to deal with the uncommon case, that's taken care of too. And it's a multimap-like, since for some of these the ordering of pairs matters too. |
Anyway, closing this given your comments. |
I think we should probably revisit this. WebKit uses CFNetwork for network requests. CFNetwork uses a map for headers and is unlikely to change. |
@hober how does it address the issues I mentioned? Could you expand on what kind of data structure that map is? |
I think this data structure is a straight <name, value> map, values being combined when trying to add headers with a same name. It supports delete, has, set (and combine which is not exposed in the fetch API). In WebKit, there is a generic headers structure used by different backends. Part of the discussion is why the fetch Headers API is exposing some information that is not meaningful at the network level, exposing this information making it potentially meaningful at the web application level. |
Well, HTTP does have a concept of multiple values that apparently CFNetwork ignores and instead always uses combining semantics. And, due to cookies, HTTP has a concept of multiple headers. How does CFNetwork deal with that? There must be some special casing somewhere. |
Is Set-Cooke the only case? That questions whether the fetch API should reflect that notion of multiple values in the API or whether that should remain a special case. |
All headers can have multiple values, in theory.
is equivalent to
I thought either |
Let's take that header set as example: If the header set is part of a response, how will be presented this data to a web application by the fetch API? If the header set is part of a request, the corresponding request at the protocol level can use one or two headers, it will be semantically equivalent. What is the benefit of enabling a web application query whether there is one combined header or two headers with the same name? |
In https://lists.w3.org/Archives/Public/www-archive/2016Jan/thread.html#msg6 several of us decided to change this API. This has the consequence that the API can never work with cookies, but that is deemed acceptable. |
Filed a follow-up to tweak the sort order on the XHR side in a case where Gecko and WebKit are now incompatible with widely-deployed buggy JS and Chrome works due to not implementing the sorting. |
Headers currently store header name value pairs as an ordered list.
If the ordering is lessened to keep only ordering between headers that have a same name, a more efficient structure could be used (ordered multimap).
In non service-worker cases at least, there seems to be little value to keep that strong ordering.
This is a follow-up of discussion from #154
The text was updated successfully, but these errors were encountered: