Avoid generating an unused Date header fallback - #13299
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #13299 +/- ##
=======================================
Coverage 99.01% 99.01%
=======================================
Files 135 135
Lines 50026 50045 +19
Branches 2611 2614 +3
=======================================
+ Hits 49531 49550 +19
Misses 371 371
Partials 124 124
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. |
Merging this PR will degrade performance by 1%
|
| Benchmark | BASE |
HEAD |
Efficiency | |
|---|---|---|---|---|
| ⚡ | test_list_element_pattern_redos_payload[whitespace_run_after_content] |
33.9 ms | 30.9 ms | +9.91% |
| 🆕 | test_prepare_web_response_headers[explicit-date] |
N/A | 7.6 ms | N/A |
| 🆕 | test_prepare_web_response_headers[generated-date] |
N/A | 8.1 ms | N/A |
| 👁 | test_read_base64_part |
14.3 ms | 16 ms | -10.83% |
Tip
Curious why this is faster? Comment @codspeedbot explain why this is faster on this PR, or directly use the CodSpeed MCP with your agent.
Comparing marcus-campbell:perf-avoid-unused-date-fallback (0993f17) with master (394959f)
Footnotes
-
83 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩
|
A note on the CodSpeed report above: "will not alter performance" is expected here, because the two benchmarks that exercise this change ( The evidence for the change is the local paired A/B run described in the PR body. |
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains. Reviews (3): Last reviewed commit: "Merge branch 'master' into perf-avoid-un..." | Re-trigger Greptile |
Backport to 3.15: 💚 backport PR created✅ Backport PR branch: Backported as #13543 🤖 @patchback |
Backport to 3.14: 💚 backport PR created✅ Backport PR branch: Backported as #13544 🤖 @patchback |
What do these changes do?
headers.setdefault(hdrs.DATE, rfc822_formatted_time())evaluates the formatter even when the response already has aDateheader, so the clock read (and possible cache refresh) happens and the result is discarded. This switches to a presence check so the formatter only runs when its value is used, and adds a regression test plus a small_prepare_headers()benchmark with and without an explicitDate.Locally, a paired A/B run showed ~0.45 µs (~2.4%) per response on the explicit-
Datepath and no measurable change on the generated-Datepath.Follow-up to #9898: that benchmark only constructed
Responseobjects and never reached_prepare_headers(), which is why CodSpeed showed no change.Are there changes in behavior for the user?
No. A user-supplied
Dateis still retained.Is it a substantial burden for the maintainers to support this?
No.
Related issue number
N/A (see #9898 above)
Checklist
required for this internal performance cleanup)
CONTRIBUTORS.txtCHANGES/folderAI assistance
Drafted with help from GPT-5.6 Sol (benchmarking, parts of this description); code by me. I've reviewed all of the code and remain responsible for the submission.