Skip to content

Iterate core metadata header values lazily - #1429

Draft
zaniebot wants to merge 2 commits into
mainfrom
zb/iterate-core-metadata-header-values-lazily
Draft

zaniebot wants to merge 2 commits into
mainfrom
zb/iterate-core-metadata-header-values-lazily

Conversation

@zaniebot

@zaniebot zaniebot commented Sep 11, 2026 •

Copy link
Copy Markdown
Collaborator

Headers::get_all_values decodes and collects matching header values into a Vec before returning an iterator. Decode values as they are consumed from astral_mail_headers::Message::all, retaining the UNKNOWN filter, and update metadata consumers to handle the fallible iterator.

Hyperfine 2.0.0 measurements of 763ac4abc → bc73f174d used release builds of the complete CLI with rustc 1.99.0 (b940084d7 2026-09-28) on an AMD EPYC-Genoa Linux VM, pinned to four CPUs. Output went to /dev/null.

Fresh uv pip show bench-header --python <environment-python> --offline processes read one synthetic installed distribution in a CPython 3.12.13 environment. Its METADATA contains zero to 10,000 active Requires-Dist headers, 100,000 Windows-only requirements, 10,000 Provides-Extra headers, or 10,000 of each Windows-only requirement and extra header. The Windows-only requirements are inactive on the Linux host.

OS pages and interpreter-query caches are warm. The complete command includes environment indexing, metadata and header parsing, requirement and extra parsing, marker evaluation and output formatting.

Values are means, parent → head. Changes are (head / parent - 1) with 95% confidence intervals; negative values indicate a reduction.

Workload Wall time Change, 95% CI Peak RSS Change, 95% CI
0 active requirement headers 15.6 → 15.3 ms -2.20% [-3.63%, -0.53%] 21.29 → 21.25 MiB -0.18% [-0.57%, +0.23%]
10 active requirement headers 15.6 → 15.5 ms -0.74% [-2.65%, +1.10%] 21.66 → 21.61 MiB -0.19% [-0.82%, +0.43%]
1,000 active requirement headers 17.4 → 16.8 ms -3.25% [-5.19%, -1.12%] 22.47 → 22.45 MiB -0.07% [-0.70%, +0.56%]
10,000 active requirement headers 31.4 → 31.5 ms +0.44% [-2.10%, +4.66%] 33.60 → 33.51 MiB -0.27% [-0.42%, -0.12%]
100,000 Windows-only requirement headers 210.4 → 198.8 ms -5.49% [-6.34%, -4.80%] 108.89 → 100.98 MiB -7.26% [-7.84%, -6.62%]
10,000 extra headers 18.1 → 17.1 ms -5.27% [-7.13%, -3.44%] 22.51 → 22.39 MiB -0.52% [-1.00%, -0.04%]
10,000 Windows-only requirements / 10,000 extra headers 36.9 → 35.5 ms -3.69% [-5.41%, -2.17%] 34.28 → 33.86 MiB -1.22% [-1.38%, -1.05%]

Each workload used ten comparison blocks with alternating revision order, one warmup followed by three measured runs per revision in each block (30 measurements per revision). The pointwise 95% percentile-bootstrap intervals use 20,000 resamples of paired block means and retain all samples. They estimate within-run uncertainty, not variation across machines, independent builds, or separate benchmark campaigns.

Wall time fell by 5.49% for 100,000 Windows-only requirements, 5.27% for 10,000 extra headers and 3.69% for the mixed case. It also fell by 3.25% for 1,000 active requirements and 2.20% in the zero-requirement control; the other two intervals include zero. Peak RSS fell by 7.26% for the 100,000-requirement case and by 0.27–1.22% for 10,000 active requirements, 10,000 extras and the mixed case; the other three RSS intervals include zero. These complete-command results do not isolate header iteration. RSS is Hyperfine's Linux wait4 peak, not an allocation count or summed simultaneous process-tree memory.

@astral-automations-bot astral-automations-bot Bot added internal A refactor or improvement that is not user-facing performance labels Sep 11, 2026
@zaniebot
zaniebot force-pushed the zb/iterate-core-metadata-header-values-lazily branch from e6ddd7f to ad02632 Compare September 11, 2026 09:24
@zaniebot zaniebot added risk:0 No meaningful change to product, state, release, or automation behavior. priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. size:0 Mechanical: little semantic reasoning; correctness is apparent from inspection or compiler checks. labels Sep 11, 2026
@zaniebot zaniebot added the project:maintainer-followups Maintainer follow-up work label Oct 9, 2026
@astral-automations-bot
astral-automations-bot Bot force-pushed the zb/iterate-core-metadata-header-values-lazily branch from ad02632 to 9c88d5c Compare October 12, 2026 16:29
Comment on lines +103 to 106
) -> impl Iterator<Item = Result<String, DecodeError>> + 'm {
self.message
.all(name)
.map(|header| header.decoded_value().map(Cow::into_owned))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

[P2] Preserve decoding errors in short-circuiting callers

Moving decoding into the iterator changes validation behavior. With otherwise valid metadata containing Dynamic: Version followed by Dynamic: =?utf-8?b?Y?=, parse_metadata now breaks before decoding the malformed value and succeeds; previously it returned DecodeError::InvalidBase64. Similarly, parse_pkg_info can return DynamicField before encountering a later decoding error, causing StaticMetadata::read to fall back to building instead of propagating the error. A requirement-parsing error can now mask a later decoding error too. Preserve decoding-error precedence by consuming the remaining matching headers before returning the saved semantic result or error, and cover a malformed later header in the tests.

@codspeed

codspeed Bot commented Oct 12, 2026 •

Copy link
Copy Markdown

Merging this PR will not alter performance

⚠️ 8 benchmarks spent significant time in system calls

System calls cannot be consistently instrumented, so they are not included in the measure, which understates the real cost. Please switch to the Walltime instrument to accurately measure system calls.

Measurement and system calls

✅ 54 untouched benchmarks
⏩ 35 skipped benchmarks1


Comparing zb/iterate-core-metadata-header-values-lazily (bc73f17) with main (45fd890)

Open in CodSpeed

Footnotes

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

@zaniebot
zaniebot deployed to automations October 13, 2026 16:46 — with GitHub Actions Active

This branch was successfully deployed

1 active deployment
automations — bc73f174 Deployed Oct 13, 2026 by zaniebot via review-code-quality / code quality review #9671
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

internal A refactor or improvement that is not user-facing performance priority:3 Normal: useful features, documentation, usability, or routine efficiency improvements. project:maintainer-followups Maintainer follow-up work risk:0 No meaningful change to product, state, release, or automation behavior. size:0 Mechanical: little semantic reasoning; correctness is apparent from inspection or compiler checks.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants