Have you tried using native compilation (9i) to speed up the function? I'm guessing that it is all computation, so it would benefit from that.