-
-
Notifications
You must be signed in to change notification settings - Fork 3.7k
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
Make get_short_name return Cow instead of String #9504
Conversation
c3a88b7
to
d5b374a
Compare
On the performance-side of things. I'll assume it's more perfs because:
|
I like this change, and agree that it should improve performance without seriously hurting complexity. Can you add a test for a non-ASCII type name to verify that it works correctly (and continues to in the future)? |
Could you rebase or merge main? There's some changes I made to schedule.rs that are conflicting. sorry 😅 |
There is also the uppercase fix (#9587), which I'm not exactly sure how to integrate in this change. |
@nicopap want me to toss Adopt-Me on this? |
Sure. Should be easy to pick up. |
Closing in favor of #12275. |
Objective
get_short_name
when not necessary. Theget_short_name
of a path without generics is strictly a subslice of the path itself, so we don't need to create a new buffer for it.get_short_name
should return aCow
most likely disqualified#2Solution
get_short_name
to work on&[u8]
instead of&str
, only returns an ownedString
when the path contains a special character.DisplayShortName
. It stores any kind of string, but when displayed, it displays theget_short_name
version.Future work
I think we could realistically replace the
GenericTypePathCell
with a streaming version ofget_short_name
that implementsHash
,Eq
etc. similarly toDisplayShortName
. It would add the parsing cost on top of hashing/equality check, but now that the parser is a lot faster, it's questionable whether the cost is actually significant.We could also replace the
CowStr
in the scheduling error type withDisplayShortName
, to lazily parse the type path only when displaying it.Changelog
get_short_name
returns aCow<str>
instead ofString
, avoiding allocation when not strictly necessary. It is also significantly more performantDisplayShortName
. It stores any kind of string, but when displayed, it displays theget_short_name
version.Migration Guide
get_short_name
returns aCow<str>
instead ofString
, add.to_string()
to the return value to get aString
. However, we recommend that if you can, you store theCow
over theString
to avoid allocations.