-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
🐛fix: update getOffer to consider quality and specificity #2486
🐛fix: update getOffer to consider quality and specificity #2486
Conversation
Considering client header priorities will have a performance impact. See discussion in #2387 |
will check this tomorrow |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Awesome, you did a good job, but I've considered two ideas to optimize your loop. Does that makes sense to you?
@sixcolors looks very good 🫶 now also understand why it is slower go test -v ./... -run=^$ -bench=Benchmark_Ctx_Accep -benchmem -count=3 Benchmark Compare:
Benchmark Old(master):
Benchmark New(PR):
you have to parse all headers first and can't run through them piece by piece because you need the order -> so the slight performance loss is okay for me can you still check the review hints in the PR otherwise it would be good if we add more test scenarios with multiple quality factors and maybe a benchmark for the getOffer method, which is the core for many others summary from above:
|
Specificity still matters even without the q value. Might not be worth the extra loops through the header to check for q and specificity... |
Can you share some benchmark numbers after these changes? |
go test -v ./... -run=^$ -bench=Benchmark_Ctx_Accep -benchmem -count=3 Benchmark Compare:
Benchmark Old(master):
Benchmark New(PR):
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Small typo in the test, but overall LGTM
@sixcolors can you do the last change with the typo |
Description
Updates the getOffer helper function so that content negotiation follows https://www.rfc-editor.org/rfc/rfc9110#name-content-negotiation-fields, specifically that quality values are considered (also where q=0 type is not acceptable) and that specificity is also considered in a tie, as a final tie breaker client order is used.
Fixes #2387
Type of change
Please delete options that are not relevant.
Checklist:
Commit formatting:
Use emojis on commit messages so it provides an easy way of identifying the purpose or intention of a commit. Check out the emoji cheatsheet here: https://gitmoji.carloscuesta.me/