Null function is the biggest perf hit?

dj_d

Member
I have a function in eatdrink.ash:
void verbose2(string foo)
{
// print(foo);
}

It gets called a lot, and I uncomment the print statement when I am doing detailed debugging (e.g. it prints the results for every consumable in the game). However, even while it's commented out, it's getting flagged as the biggest net time-spent function in the game. Two questions:
1) Why is a no-op function taking so long to execute?
2) How can I accomplish the same result without the perf hit?
 

jasonharper

Developer
First rule of optimization: the time is never being taken by what you expected...

ASH performs a 1 millisecond pause at the top of each code block (function, loop body, etc.), to give other threads a chance to run. This ensures that the UI remains usable, and in particular guarantees that you'll always be able to click Stop or hit ESC to cancel a script - even if it's hung in a tight loop, and you're using a Java version with crappy thread handling. A millisecond doesn't seem like much, but they do add up - and your no-op function would otherwise take at most a few microseconds to run.

Give r7724 a try - it performs the pause at most 10 times per second, so at most 1% of the script execution time gets wasted.
 

dj_d

Member
I'll be darned. That makes sense - it's being called about 6,000 times. Standing by for Herr Buildbot to deliver 7724.
 

dj_d

Member
Um - wow. The whole script now executes in 10 seconds, down from 100 (if you don't have any mall_price hits). HUGE improvement.

farm.ash sped up quite a bit too.
 
Top