-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Extra level of indirection with explicit self #4402
Labels
A-codegen
Area: Code generation
A-trait-system
Area: Trait system
I-slow
Issue: Problems and improvements with respect to performance of generated code.
Comments
The long and immediate IRC discussion: |
Changing the name of this bug to make it actionable. |
Why is this backwards incompatible? |
Nominating to change status, I don't think this is a backwards compat issue. |
accepted for production-ready milestone |
dotdash
added a commit
to dotdash/rust
that referenced
this issue
Jun 29, 2013
Currently we pass all "self" arguments by reference, for the pointer variants this means that we end up with double indirection which causes a unnecessary performance hit. The fix itself is pretty straight-forward and just means that "self" needs to be handled like any other argument, except for by-value "self" which still needs to be passed by reference. This is because non-pointer types can't just be stuffed into the environment slot which is used to pass "self". What made things tricky is that there was also a bug in the typechecker where the method map entries are created. For type impls, that stored the base type instead of the actual self-type in the method map, e.g. Foo instead of &Foo for &self. That worked with pass-by-reference, but fails with pass-by-value which needs the real type. Code that makes use of methods seems to be about 10% faster with this change. Also, build times are reduced by about 4%. Fixes rust-lang#4355, rust-lang#4402, rust-lang#5280, rust-lang#4406 and rust-lang#7285
bors
added a commit
that referenced
this issue
Jun 29, 2013
Currently we pass all "self" arguments by reference, for the pointer variants this means that we end up with double indirection which causes a unnecessary performance hit. The fix itself is pretty straight-forward and just means that "self" needs to be handled like any other argument, except for by-value "self" which still needs to be passed by reference. This is because non-pointer types can't just be stuffed into the environment slot which is used to pass "self". What made things tricky is that there was also a bug in the typechecker where the method map entries are created. For type impls, that stored the base type instead of the actual self-type in the method map, e.g. Foo instead of &Foo for &self. That worked with pass-by-reference, but fails with pass-by-value which needs the real type. Code that makes use of methods seems to be about 10% faster with this change. Also, build times are reduced by about 4%. Fixes #4355, #4402, #5280, #4406 and #7285
Fixed by #7452. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
A-codegen
Area: Code generation
A-trait-system
Area: Trait system
I-slow
Issue: Problems and improvements with respect to performance of generated code.
I found a multi-language benchmark online (https://gist.github.com/1170424) whose Rust version was outdated. I decided to update it.
Here's the original code:
I noticed that updating this code to use explicit self causes a noticeable perf hit, even though nmatsakis assures me that the semantics should be the same. For posterity, here's the updated version (the only difference is that the three methods are using explicit
&self
parameters):Both versions were compiled with
rustc --opt-level=3
and profiled as follows:orig.txt:
expself.txt:
@nikomatsakis has a theory:
The text was updated successfully, but these errors were encountered: