Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy up some uses of Bound<'_, PyString>::to_str #1544

Merged
merged 1 commit into from
Nov 19, 2024
Merged

Conversation

davidhewitt
Copy link
Contributor

Change Summary

Inspired by pydantic/jiter#166 I had a quick look to see if similar uses could be optimised in core.

Related issue number

N/A

Checklist

  • Unit tests for the changes exist
  • Documentation reflects the changes where applicable
  • Pydantic tests pass with this pydantic-core (except for expected changes)
  • My PR is ready to review, please add a comment including the phrase "please review" to assign reviewers

Copy link

codspeed-hq bot commented Nov 19, 2024

CodSpeed Performance Report

Merging #1544 will not alter performance

Comparing dh/to-str-tidy (ff9f426) with main (6472887)

Summary

✅ 155 untouched benchmarks

Comment on lines -612 to -615
ObType::Str | ObType::StrSubclass => {
let py_str = key.downcast::<PyString>()?;
Ok(Cow::Owned(py_str.to_str()?.to_string()))
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

While most of this diff is within noise of allocations elsewhere in the system, removing this allocation does show a teeny tiny improvement here:

image

Copy link
Member

@sydney-runkle sydney-runkle left a comment

Choose a reason for hiding this comment

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

Cool, thanks!

@davidhewitt davidhewitt merged commit 30f6f55 into main Nov 19, 2024
28 of 29 checks passed
@davidhewitt davidhewitt deleted the dh/to-str-tidy branch November 19, 2024 14:53
@sydney-runkle
Copy link
Member

Huh, what are those test failures about?

@davidhewitt
Copy link
Contributor Author

(For future readers, test failures were integration issues fixed by #1545)

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