Thank you for your post into the forum.
I have known when working with a large script that performance falls off when away from the caret.
So I can reproduce the error, would it be possible to get a copy of your SP?
A support call has been created for you, the call reference number is F0057164. If you could please attached a copy of your SP as a text file to an e-mail, I can then modify it to see if I can reproduce your error. Also if you can include in the e-mail, the version of SQL Server you are using?
Please send the e-mail to firstname.lastname@example.org
and include the call reference number in the subject field of the e-mail.