Optimizes backtrace generation algorithm