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

Slightly optimise CString #37622

Merged
merged 1 commit into from
Nov 9, 2016
Merged

Slightly optimise CString #37622

merged 1 commit into from
Nov 9, 2016

Conversation

ollie27
Copy link
Member

@ollie27 ollie27 commented Nov 6, 2016

Avoid a reallocation in CString::from and CStr::to_owned.

@rust-highfive
Copy link
Collaborator

r? @brson

(rust_highfive has picked a reviewer for you, use r? to override)

@alexcrichton
Copy link
Member

Thanks for the PR! Are you worried about any particular function for #[inline]? I'd prefer to avoid adding the tag to basically all of them as it can have serious effects on downstream consumers, but adding a few select ones should be fine.

@alexcrichton
Copy link
Member

Also, do you have benchmarks to back up the unsafe additions of eliding bounds checking?

@ollie27
Copy link
Member Author

ollie27 commented Nov 8, 2016

Are you worried about any particular function for #[inline]? I'd prefer to avoid adding the tag to basically all of them as it can have serious effects on downstream consumers, but adding a few select ones should be fine.

Not really, I just noticed that calling as_ptr on a CString made two function calls (one to deref and one to CStr::as_ptr), now it's just a pointer copy as expected even without lto. I've only added #[inline] to trivial functions and functions which basically just make a library call. Are there any special rules about what should be marked #[inline] in std?

Also, do you have benchmarks to back up the unsafe additions of eliding bounds checking?

I unfortunately haven't been able to see any difference from removing the bounds checks, only a possible tiny improvement from inlining. It probably doesn't matter much so I can remove it if you think it's too risky, I just noticed it in the assembly and thought we may as well remove some unnecessary instructions.

@alexcrichton
Copy link
Member

We tend to avoid #[inline] wherever possible as it tends to lead to bloated compile times (more for LLVM to work with), so we prefer to see numeric improvements when adding the tags. It's true most of these functions are trivial, thought.

We also tend to prefer only using unsafe code for optimizations if we can show the improvement we're getting in perf, but if that's not the case here perhaps that could be backed out for now?

Avoid a reallocation in CString::from and CStr::to_owned.
@ollie27
Copy link
Member Author

ollie27 commented Nov 8, 2016

I've removed the inlining and bounds check removal. They weren't very important anyway. The use of #[inline] in std does seem to be very inconsistent.

@alexcrichton
Copy link
Member

@bors: r+

Yes #[inline] application has historically been very liberal in the past, but recently we've had renewed interest in cracking down

@bors
Copy link
Contributor

bors commented Nov 8, 2016

📌 Commit 18f5f99 has been approved by alexcrichton

eddyb added a commit to eddyb/rust that referenced this pull request Nov 9, 2016
Slightly optimise CString

Avoid a reallocation in CString::from and CStr::to_owned.
bors added a commit that referenced this pull request Nov 9, 2016
Rollup of 15 pull requests

- Successful merges: #36868, #37134, #37229, #37250, #37370, #37428, #37432, #37472, #37524, #37614, #37622, #37627, #37636, #37644, #37654
- Failed merges: #37463, #37542, #37645
@bors bors merged commit 18f5f99 into rust-lang:master Nov 9, 2016
@ollie27 ollie27 deleted the cstring branch November 11, 2016 18:34
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.

5 participants