[PR #13299/5fa85842 backport][3.14] Avoid generating an unused Date header fallback by patchback[bot] · Pull Request #13544 · aio-libs/aiohttp · GitHub
Skip to content

[PR #13299/5fa85842 backport][3.14] Avoid generating an unused Date header fallback - #13544

Merged
Dreamsorcerer merged 2 commits into
3.14from
patchback/backports/3.14/5fa85842951ad68b2cba0bbc511dad1eca90cd3a/pr-13299
Aug 25, 2026
Merged

Dreamsorcerer merged 2 commits into
3.14from
patchback/backports/3.14/5fa85842951ad68b2cba0bbc511dad1eca90cd3a/pr-13299

Conversation

@patchback

@patchback patchback Bot commented Aug 24, 2026

Copy link
Copy Markdown
Contributor

This is a backport of PR #13299 as merged into master (5fa8584).

What do these changes do?

headers.setdefault(hdrs.DATE, rfc822_formatted_time()) evaluates the formatter even when the response already has a Date header, 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 explicit Date.

Locally, a paired A/B run showed ~0.45 µs (~2.4%) per response on the explicit-Date path and no measurable change on the generated-Date path.

Follow-up to #9898: that benchmark only constructed Response objects and never reached _prepare_headers(), which is why CodSpeed showed no change.

Are there changes in behavior for the user?

No. A user-supplied Date is still retained.

Is it a substantial burden for the maintainers to support this?

No.

Related issue number

N/A (see #9898 above)

Checklist

  • I think the code is well written
  • Unit tests for the changes exist
  • Documentation reflects the changes (no user-facing documentation change is
    required for this internal performance cleanup)
  • If you provide code modification, please add yourself to CONTRIBUTORS.txt
  • Add a new news fragment into the CHANGES/ folder

AI 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.

Co-authored-by: J. Nick Koston <nick@koston.org>
(cherry picked from commit 5fa8584)
@greptile-apps

greptile-apps Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Comment thread tests/test_benchmarks_web_response.py Outdated
@codecov

codecov Bot commented Aug 24, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 96.21%. Comparing base (4281195) to head (9ac3f0c).
⚠️ Report is 1 commits behind head on 3.14.
✅ All tests successful. No failed tests found.

Additional details and impacted files
@@            Coverage Diff             @@
##             3.14   #13544      +/-   ##
==========================================
- Coverage   96.22%   96.21%   -0.02%     
==========================================
  Files         160      160              
  Lines       51079    51133      +54     
  Branches     2761     2778      +17     
==========================================
+ Hits        49151    49196      +45     
- Misses       1751     1756       +5     
- Partials      177      181       +4     
Flag Coverage Δ
CI-GHA 96.20% <100.00%> (-0.03%) ⬇️
OS-Linux 95.98% <100.00%> (-0.04%) ⬇️
OS-Windows 93.69% <100.00%> (-0.04%) ⬇️
OS-macOS 95.18% <100.00%> (-0.03%) ⬇️
Py-3.10 95.35% <100.00%> (-0.06%) ⬇️
Py-3.11 95.60% <100.00%> (-0.07%) ⬇️
Py-3.12 95.67% <100.00%> (-0.06%) ⬇️
Py-3.13 95.66% <100.00%> (-0.06%) ⬇️
Py-3.14 95.78% <100.00%> (-0.05%) ⬇️
Py-3.14t 94.78% <100.00%> (-0.05%) ⬇️
Py-pypy-3.11 94.62% <100.00%> (-0.06%) ⬇️
VM-macos 95.18% <100.00%> (-0.03%) ⬇️
VM-ubuntu 95.98% <100.00%> (-0.04%) ⬇️
VM-windows 93.69% <100.00%> (-0.04%) ⬇️
cython-coverage 78.94% <100.00%> (-0.09%) ⬇️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

Comment thread tests/test_benchmarks_web_response.py Outdated
Co-authored-by: Sam Bull <aa6bs0@sambull.org>
@codspeed

codspeed Bot commented Aug 25, 2026 •

Copy link
Copy Markdown

Merging this PR will degrade performance by 14.74%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

❌ 1 (👁 1) regressed benchmark
✅ 77 untouched benchmarks
🆕 2 new benchmarks
⏩ 7 skipped benchmarks1

Performance Changes

Benchmark BASE HEAD Efficiency
🆕 test_prepare_web_response_headers[pyloop-explicit-date] N/A 1.9 ms N/A
🆕 test_prepare_web_response_headers[pyloop-generated-date] N/A 2 ms N/A
👁 test_read_base64_part[pyloop] 4.4 ms 5.2 ms -14.74%

Comparing patchback/backports/3.14/5fa85842951ad68b2cba0bbc511dad1eca90cd3a/pr-13299 (9ac3f0c) with 3.14 (e6700fa)

Open in CodSpeed

Footnotes

  1. 7 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. ↩

@Dreamsorcerer
Dreamsorcerer merged commit e3640af into 3.14 Aug 25, 2026
47 checks passed
@Dreamsorcerer
Dreamsorcerer deleted the patchback/backports/3.14/5fa85842951ad68b2cba0bbc511dad1eca90cd3a/pr-13299 branch August 25, 2026 00:28
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