Skip to content

Stack growth defeats optimization #1527

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
brson opened this issue Jan 15, 2012 · 6 comments
Closed

Stack growth defeats optimization #1527

brson opened this issue Jan 15, 2012 · 6 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 Jan 15, 2012

After adding a call to fib(42) in shootout-fibo's main function.

Without -O:

real    0m3.098s
user    0m3.080s
sys     0m0.010s

With -O:

real    0m5.799s
user    0m5.770s
sys     0m0.020s

Edit: When tasks do a lot of calculations without using a lot of stack, the effects of growing and shrinking the stack appear to have terrible results.

@brson
Copy link
Contributor Author

brson commented Jan 15, 2012

I'm having a hard time understanding what I'm seeing. The above numbers are with the following main function:

fn main() { 
    assert (fib(8) == 21); 
    assert (fib(15) == 610);                        
    fib(42);                     
    log(debug, fib(8));                               
    log(debug, fib(15));                         
}

If I instead use this main function:

fn main() {                                                  
    fib(42);                                                 
}

Thin I get the following results with -O:

real    0m8.432s
user    0m8.390s
sys     0m0.030s

It should be doing less work but it's taking longer.

@brson
Copy link
Contributor Author

brson commented Jan 15, 2012

With the smaller main function for some reason a lot of time ends up being spent in check_stack_canary.

@brson
Copy link
Contributor Author

brson commented Jan 15, 2012

check_stack_canary does take a lot of time, but removing it doesn't change the general behavior here that -O is slower and the smaller main function is slower.

@brson
Copy link
Contributor Author

brson commented Jan 15, 2012

Setting RUST_MIN_STACK=1000000 results in the optimized code being much faster.

@brson
Copy link
Contributor Author

brson commented Jan 15, 2012

My guess is that the optimized code needs less stack, so it spends more time at the bottom of the stack where segments are smaller, and ends up making more requests to grow/shrink the stack

brson added a commit that referenced this issue Jan 15, 2012
Adding this back to the library as a stopgap measure to recover some benchmark
performance. See #1527.
@brson
Copy link
Contributor Author

brson commented Mar 22, 2012

I checked in some optimizations to stack growth that makes it perform much better. The optimized version of fib is still slightly worse than the unoptimized one, but I don't what else to do about it.

@brson brson closed this as completed Mar 22, 2012
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

1 participant