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

Switching to the C stack is slow #1801

Closed
brson opened this issue Feb 10, 2012 · 7 comments
Closed

Switching to the C stack is slow #1801

brson opened this issue Feb 10, 2012 · 7 comments
Labels
A-codegen Area: Code generation A-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-slow Issue: Problems and improvements with respect to performance of generated code.

Comments

@brson
Copy link
Contributor

brson commented Feb 10, 2012

pcwalton saw the C-stack-switching __morestack function show up surprisingly high on profiles. All this function does is change sp and call a function by pointer. Probably this is very bad for branch prediction.

@brson
Copy link
Contributor Author

brson commented Feb 10, 2012

Branch prediction is the reason the stack-growth __morestack function has such a bizarre structure.

@brson
Copy link
Contributor Author

brson commented Feb 10, 2012

Possibly we can just use the stack-growth __morestack function to do stack switching as well by setting the stack boundary to a value that is guaranteed to trip the call to __morestack and setting a flag in the task structure to put it into a different 'mode'. This would make branch prediction work and eliminate the need to marshall arguments through a struct on the stack.

@ghost ghost assigned brson Apr 12, 2012
@brson
Copy link
Contributor Author

brson commented Jul 31, 2012

We tried using __morestack for this and it had too much overhead from other stack growth code to make it worthwhile.

@emberian
Copy link
Member

Visiting for triage; still relevant.

@huonw
Copy link
Member

huonw commented Aug 28, 2013

Triage: #8535 changed (some of) the way extern fns work, so I have no idea if this is valid, and I can't create a testcase that reproduces it (possibly because segmented stacks are disabled in the new rt?).

@nikomatsakis would your changes have affected this?

@nikomatsakis
Copy link
Contributor

@huonw yes and no. We no longer use the old C stack switching mechanism, we only use the "stack-growth" variant of __morestack. Moreover, users can now move the stack switch so it occurs earlier, which helps to eliminate overhead. However, the mechanism itself is still probably too slow -- though whether it can be further optimized is unclear, @pcwalton thought no. Certainly we can't eliminate the megamorphic call site that Brian referred to.

@catamorphism
Copy link
Contributor

Obsolete

celinval added a commit to celinval/rust-dev that referenced this issue Jun 4, 2024
Add tests for rust-lang#564, rust-lang#208 and rust-lang#87.

Unfortunately, it looks like there are still issues with with how we are
encoding panic threads and dynamic objects which are causing two of the
test cases to fail.
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-runtime Area: std's runtime and "pre-main" init for handling backtraces, unwinds, stack overflows I-slow Issue: Problems and improvements with respect to performance of generated code.
Projects
None yet
Development

No branches or pull requests

5 participants