How do you expect us to do that, with no access to your SP or your data?
We can't help with no information, and even with your SP we probably couldn't help either as it's almost certain that you'd need your data available in order to profile the SP in any detail - and any SP which takes 40 seconds is processing a lot of data!
So start by profiling what you are doing:
progfiling stored procedures and memory usage - Google Search[
^] and see where the bottleneck is.
Sorry, but we can't do that for you!