Skip to content

Use Cow<str> for deserialization everywhere#17330

Merged
woodruffw merged 5 commits intomainfrom
ww/more-cow
Jan 5, 2026
Merged

Use Cow<str> for deserialization everywhere#17330
woodruffw merged 5 commits intomainfrom
ww/more-cow

Conversation

@woodruffw
Copy link
Member

Summary

Switches all String::deserialize callsites to <Cow<'_, &str>> for opportunistic borrowing. This should be advantageous for us in cases where we immediately discard the String anyways, e.g. any sort of parse(s: &str) -> T call.

See #17327 and onwards for context.

Test Plan

NFC.

Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw requested a review from zanieb January 5, 2026 21:11
@woodruffw woodruffw self-assigned this Jan 5, 2026
@woodruffw woodruffw added performance Potential performance improvement internal A refactor or improvement that is not user-facing labels Jan 5, 2026
Signed-off-by: William Woodruff <william@astral.sh>
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw temporarily deployed to uv-test-registries January 5, 2026 21:31 — with GitHub Actions Inactive
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw temporarily deployed to uv-test-registries January 5, 2026 21:35 — with GitHub Actions Inactive
Signed-off-by: William Woodruff <william@astral.sh>
@woodruffw woodruffw temporarily deployed to uv-test-registries January 5, 2026 22:03 — with GitHub Actions Inactive
let normalized = PackageName::from_str(&given).map_err(serde::de::Error::custom)?;
Ok(Self { given, normalized })
Ok(Self {
given: given.to_string(),
Copy link
Member

Choose a reason for hiding this comment

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

This seems marginal since we allocate anyway? (Maybe we should use ArcStr for the given name.)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, this one is marginal. I'll look at ArcStr in a follow-up 🙂

@woodruffw woodruffw merged commit a27e0c8 into main Jan 5, 2026
102 checks passed
@woodruffw woodruffw deleted the ww/more-cow branch January 5, 2026 22:57
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 Potential performance improvement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants