Make get_short_name return Cow instead of String#9504
Closed
nicopap wants to merge 2 commits intobevyengine:mainfrom
Closed
Make get_short_name return Cow instead of String#9504nicopap wants to merge 2 commits intobevyengine:mainfrom
nicopap wants to merge 2 commits intobevyengine:mainfrom
Conversation
c3a88b7 to
d5b374a
Compare
Contributor
Author
|
On the performance-side of things. I'll assume it's more perfs because:
|
Member
|
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)? |
alice-i-cecile
approved these changes
Aug 20, 2023
Contributor
|
Could you rebase or merge main? There's some changes I made to schedule.rs that are conflicting. sorry 😅 |
Contributor
Author
|
There is also the uppercase fix (#9587), which I'm not exactly sure how to integrate in this change. |
Member
|
@nicopap want me to toss Adopt-Me on this? |
Contributor
Author
Sure. Should be easy to pick up. |
Member
|
Closing in favor of #12275. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Objective
get_short_namewhen not necessary. Theget_short_nameof 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_nameshould return aCowmost likely disqualified#2Solution
get_short_nameto work on&[u8]instead of&str, only returns an ownedStringwhen the path contains a special character.DisplayShortName. It stores any kind of string, but when displayed, it displays theget_short_nameversion.Future work
I think we could realistically replace the
GenericTypePathCellwith a streaming version ofget_short_namethat implementsHash,Eqetc. 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
CowStrin the scheduling error type withDisplayShortName, to lazily parse the type path only when displaying it.Changelog
get_short_namereturns 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_nameversion.Migration Guide
get_short_namereturns aCow<str>instead ofString, add.to_string()to the return value to get aString. However, we recommend that if you can, you store theCowover theStringto avoid allocations.