Skip to content

fix(compose): skip the lowered-environment allocation in envResolverWithCase - #14390

Merged
ndeloof merged 1 commit into
docker:mainfrom
TDnorthgarden:fix/envresolver-lazy-fold
Oct 26, 2026
Merged

ndeloof merged 1 commit into
docker:mainfrom
TDnorthgarden:fix/envresolver-lazy-fold

Conversation

@TDnorthgarden

Copy link
Copy Markdown
Contributor

Problem

On the case-insensitive path (Windows), envResolverWithCase builds a
lower-cased copy of the whole environment map up front, before any lookup
happens — even when every lookup ends up hitting a key directly. That is an
unconditional len(environment) allocation per resolver, paid before
knowing whether the fallback is ever needed.

Fix

As suggested by @thaJeztah in #14388:

  • the exact lookup stays an O(1) map hit and runs first;
  • only on a miss does it scan the original map with strings.EqualFold —
    no copy, nothing allocated on the common path;
  • folded-key conflicts (e.g. FOO and foo both set) were already
    documented as indefinite and stay so: the test now pins that contract
    (a folded lookup resolves, to one of the folded values) and the
    exact-match precedence over folded keys.

…ithCase

envResolverWithCase unconditionally built a lower-cased copy of the whole
environment map before any lookup, even when every lookup hits a key
directly. Fall back to a case-insensitive scan (strings.EqualFold) of the
original map only when the exact lookup misses, so the common path
allocates nothing.

Folded-key conflicts (e.g. FOO and foo both present) were already
documented as indefinite and remain so.

Signed-off-by: Aucoto <tdnorthgarden@gmail.com>
@TDnorthgarden
TDnorthgarden requested review from a team as code owners October 26, 2026 09:47
@ndeloof
ndeloof enabled auto-merge (rebase) October 26, 2026 10:43

@ndeloof ndeloof left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM. I checked the branch locally: exact match keeps precedence and the folded fallback behaves as before for non-conflicting keys.

Non-blocking note: when two keys differ only by case (e.g. FOO and foo), the value picked is still "indefinite" as documented, but it is now chosen per lookup rather than once per resolver (map iteration order), so the same resolver can return either value across calls. Fine given the documented contract and how rare the case is; no change requested.

@ndeloof
ndeloof merged commit 0c7f8a3 into docker:main Oct 26, 2026
61 of 63 checks passed
@codecov

codecov Bot commented Oct 26, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

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