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

Make performance description of String::insert_str more precise #138538

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

hkBst
Copy link
Member

@hkBst hkBst commented Mar 15, 2025

No description provided.

@rustbot
Copy link
Collaborator

rustbot commented Mar 15, 2025

r? @joboet

rustbot has assigned @joboet.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Mar 15, 2025
@hkBst hkBst changed the title Make performance of String::insert_str more precise Make performance description of String::insert_str more precise Mar 17, 2025
Copy link
Member

@joboet joboet left a comment

Choose a reason for hiding this comment

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

I don't really see why anyone would need such precise numbers, it's not like you could correlate that with an exact cycle number or something.

Still, the old note is not correct. I recommend you adapt the old note to say something about the tail of the string needing to be shifted – that is probably the most helpful information to anyone investigating a performance issue in their code.

/// This is an *O*(*n*) operation as it requires copying every element in the
/// buffer.
/// If there is space in `self` this will copy `self.len() - idx + string.len()` bytes,
/// otherwise will reallocate and copy `self.len() + string.len()` bytes.
Copy link
Member

Choose a reason for hiding this comment

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

This is incorrect – the reallocation case potentially copies self.capacity() bytes and then additionally self.len() - idx + string.len() bytes.

@rustbot rustbot added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Mar 17, 2025
@the8472
Copy link
Member

the8472 commented Mar 17, 2025

Being too specific also has the downside that it's essentially specifying the implementation, thus constraining future implementation changes. What is documented generally is a guarantee.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. T-libs Relevant to the library team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants