Skip to content

Walk the parents of the path once in MapAllEqualOrContainingPathMap - #4812

Merged
emcfarlane merged 2 commits into
bufbuild:mainfrom
g4lb:normalpath-walk-parents-once
Nov 26, 2026
Merged

emcfarlane merged 2 commits into
bufbuild:mainfrom
g4lb:normalpath-walk-parents-once

Conversation

@g4lb

@g4lb g4lb commented Nov 26, 2026

Copy link
Copy Markdown
Contributor

MapAllEqualOrContainingPathMap runs twice per image file when --path names a directory. For each map key, it walked all parents of the path again. Now it walks the parents once and stops when all keys match. The result does not change.

Case Time
NewImageWithOnlyPathsAllowNotExistDirOnly 774 → 624 µs (−19%)
Map of 100 dirs, deep path 55.4 → 0.74 µs (−99%)
Map of 100 dirs, short path 13.4 → 0.27 µs (−98%)
Map of 100 dirs, no match 13.1 → 0.20 µs (−98%)
Map of 10 dirs 1.53 → 0.27 µs (−82%)
Path is . 107 → 52 ns (−52%)
Map has . 343 → 222 ns (−35%)
Map of 1 dir, no match 272 → 250 ns (−8%)

Map rows use a local benchmark. Other cases, bytes and allocs did not change. No benchmark was slower in all 3 code layouts (AMD EPYC 7763, Go 1.27.4). Old and new results matched on 2M random inputs.

@CLAassistant

CLAassistant commented Nov 26, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@emcfarlane emcfarlane 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.

Thanks! Added a similar fix (although unable to directly compare within the map) for windows.

@emcfarlane
emcfarlane merged commit f9a5d3d into bufbuild:main Nov 26, 2026
10 checks passed
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.

3 participants