Skip to content

expose expect intrinsics + mark push slow path #17317

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

Closed
wants to merge 1 commit into from
Closed

expose expect intrinsics + mark push slow path #17317

wants to merge 1 commit into from

Conversation

thestinger
Copy link
Contributor

This marks the slow path in the Vec<T> push function, improviding
code generation by moving it out of fast paths. The push function is
inlined in countless locations and not all of them order these blocks
appropriately without a hint. This improves the performance of the
microbenchmark in #15177 by 15% when dirty page purging is disabled.

Exposing the i1 version of the intrinsic for bool would be useful, but
the quirks of Rust's code generation prevent it from becoming branch
metadata so it has been left out for now.

A more sophisticated approach could be taken in the future (#11092) but
this provides a useful optimization feature today.

@alexcrichton
Copy link
Member

This seems odd to only expose these macros as part of the libcore prelude, as there's basically no other core functionality that's present in the libcore prelude and not in the std prelude. Note, however, std prelude changes require an RFC.

@thestinger
Copy link
Contributor Author

@alexcrichton: It's a performance optimization. These are intended to be marked as #[experimental], and AFAIK adding a useful feature like an optimization behind that stability flag is fine without an RFC - the compiler doesn't understand that for macros right now, which isn't just a problem for these.

@thestinger thestinger added the I-slow Issue: Problems and improvements with respect to performance of generated code. label Sep 16, 2014
@alexcrichton
Copy link
Member

Oh dear, sorry for being a little slow to get back to you on this, it seems to have fallen through the cracks in my inbox!

Our current policy on modifying the prelude is to require an RFC. The threshold for something going into the prelude is that it needs absolutely overwhelming evidence that it should be in the prelude. It's an unfortunate side effect that currently all macros are "in the prelude" by virtue of being a macro. (would it be possible for these to be a function?). Some examples in the past where we've required an RFC are:

This marks the slow path in the `Vec<T>` `push` function, improviding
code generation by moving it out of fast paths. The `push` function is
inlined in countless locations and not all of them order these blocks
appropriately without a hint. This improves the performance of the
microbenchmark in #15177 by 15% when dirty page purging is disabled.

Exposing the i1 version of the intrinsic for `bool` would be useful, but
the quirks of Rust's code generation prevent it from becoming branch
metadata so it has been left out for now.

A more sophisticated approach could be taken in the future (#11092) but
this provides a useful optimization feature today.
@wycats
Copy link
Contributor

wycats commented Oct 8, 2014

This just seems like a limitation in stability markers. It doesn't seem like @thestinger is trying to create a new public API, but the current implementation doesn't offer a way to mark the new macro as unstable or internal.

It doesn't seem like that should block this performance improvement.

@thestinger
Copy link
Contributor Author

It can't be a function because lower-expect is a function pass. The expect markers are gone by the time inlining starts.

@alexcrichton
Copy link
Member

@wycats yes, it's not supposed to be a public API, but that's the way macros work right now. As-is we require an RFC to modify the prelude (which includes macros right now), and we have precedent for holding off small performance improvements such as this because of macros (see #17857 and #16204).

Yes, this is unfortunate, and it's not the state of affairs we'd like to have, but it's an unavoidable reality with today's macro system.

@thestinger
Copy link
Contributor Author

I'll put these in an #[experimental] crate instead of the prelude then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants