ID:2062463
Mar 31 2016, 12:19 pm
|
|
Can I reduce the number of times stat() is called . It seems like this is eating up tons of cpu over a short amount of time. How could I reduce the self cpu and reduce the number of calls.
|
Self CPU in Stat() is going to be based on what you're doing in the proc. If you can show us the proc I'm sure we can come up with ways to improve it. But you can't really get Stat() to be called less often.
|
For simplicity and ease of reading, I'm going to paste that code in a DM block here.
mob/human Basically the problem is you're trying to do way too much stuff in Stat() that it was never designed for, and you're also outputting text that doesn't need to be done all the time. So, first off: That's a lot of usr abuse. While Stat() is in theory usr-safe, you don't need it; use src instead, and then this is all easier. Stat() does not need to be a background proc. That is so wrong. Get rid of the set background line. Sleeping right off the bat is also not something you want to do. Get rid of that. Outputting the current stats to a grid is all well and good, but--and though I've been guilty of this too--I recommend moving all that to something else. In particular, you really don't need to output all those values all the time; you only need to output the ones that have changed. You can do that when they change, which is easier. The call to updateBars() is the same deal. That shouldn't need to be done constantly. The logic around stunning, etc. is all better handled in a simple update loop than in Stat(). Never, ever put a space around the = in HTML tag attributes. This is not cool. Seriously, Dante wrote about what happened to people who do that. |
If Stat() is using too much CPU, then you should just reduce the amount of computation that occurs in it. You probably don't have to compute every value shown, every call.