ID:2062463
 
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.
The frequency of calls depends on (but isn't equal to) world.fps.

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.
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
Stat()
set background = 1

if(!usr.client || !usr.initialized)

usr.statLoop_active = true

sleep(1)

var
grid = 0
rate = 5
level = blevel; experience = body
funds = money; faction_points = factionpoints
max_stamina = stamina
max_chakra = chakra
wounds = curwound; max_wounds = maxwound
str_ = str; str_buff = strbuff; str_debuff = strneg
con_ = con; con_buff = conbuff; con_debuff = conneg
rfx_ = rfx; rfx_buff = rfxbuff; rfx_debuff = rfxneg
int_ = int; int_buff = intbuff; int_debuff = intneg

rate = src.level_rate



usr << output("Stamina", "stats_grid:[++grid],1")
usr << output("[curstamina]/[stamina] ([staminaregen>=0?"+[staminaregen]":"[staminaregen]"])", "stats_grid:[grid],2")
usr << output("Chakra", "stats_grid:[++grid],1")
usr << output("[curchakra]/[chakra] ([chakraregen>=0?"+[chakraregen]":"[chakraregen]"])", "stats_grid:[grid],2")
usr << output("Wounds", "stats_grid:[++grid],1")
usr << output("[curwound]/[maxwound]", "stats_grid:[grid],2")
usr << output("Strength", "stats_grid:[++grid],1")
usr << output("[round(str+strbuff-strneg)]", "stats_grid:[grid],2")
usr << output("Control", "stats_grid:[++grid],1")
usr << output("[round(con+conbuff-conneg)]", "stats_grid:[grid],2")
usr << output("Reflex", "stats_grid:[++grid],1")
usr << output("[round(rfx+rfxbuff-rfxneg)]", "stats_grid:[grid],2")
usr << output("Intelligence", "stats_grid:[++grid],1")
usr << output("[round(int+intbuff-intneg)]", "stats_grid:[grid],2")

if(!usr.client) return

winset(usr, "stats_grid", "cells = [grid]x2")

grid = 0
usr << output("Level", "full_stats_grid:1,[++grid]")
usr << output("[blevel]", "full_stats_grid:2,[grid]")
usr << output("Experience", "full_stats_grid:1,[++grid]")
usr << output("[body]/[Req2Level(blevel,src)]\n(Rate:[rate*lp_mult])", "full_stats_grid:2,[grid]")
usr << output("Stamina", "full_stats_grid:1,[++grid]")
usr << output("[curstamina]/[stamina]\n([staminaregen>=0?"+[staminaregen]":"[staminaregen]"] regen)", "full_stats_grid:2,[grid]")
usr << output("Chakra", "full_stats_grid:1,[++grid]")
usr << output("[curchakra]/[chakra]\n([chakraregen>=0?"+[chakraregen]":"[chakraregen]"] regen)", "full_stats_grid:2,[grid]")
usr << output("Wounds", "full_stats_grid:1,[++grid]")
usr << output("[curwound]/[maxwound]", "full_stats_grid:2,[grid]")
usr << output("Strength", "full_stats_grid:1,[++grid]")
usr << output("[round(str)] (+[strbuff] -[strneg])", "full_stats_grid:2,[grid]")
usr << output("Control", "full_stats_grid:1,[++grid]")
usr << output("[round(con)] (+[conbuff] -[conneg])", "full_stats_grid:2,[grid]")
usr << output("Reflex", "full_stats_grid:1,[++grid]")
usr << output("[round(rfx)] (+[rfxbuff] -[rfxneg])", "full_stats_grid:2,[grid]")
usr << output("Intelligence", "full_stats_grid:1,[++grid]")
usr << output("[round(int)] (+[intbuff] -[intneg])", "full_stats_grid:2,[grid]")
usr << output("Ryo", "full_stats_grid:1,[++grid]")
usr << output("[money]", "full_stats_grid:2,[grid]")
usr << output("Faction Points", "full_stats_grid:1,[++grid]")
usr << output("[factionpoints]", "full_stats_grid:2,[grid]")

if(usr.clan == "Steam User")
usr << output("<font color = white>Steam Power", "full_stats_grid:1,[++grid]")
usr << output("<font color = white>[steam_power]", "full_stats_grid:2,[grid]")

usr << output("Rank Grade", "full_stats_grid:1,[++grid]")
usr << output("[ninrank]", "full_stats_grid:2,[grid]")
usr << output("Weight", "full_stats_grid:1,[++grid]")
usr << output("[weight]/200", "full_stats_grid:2,[grid]")

usr << output("Trait", "full_stats_grid:1,[++grid]")
usr << output("[trait]", "full_stats_grid:2,[grid]")

if(usr.clan == "Collector")
usr << output("Eye Count", "full_stats_grid:1,[++grid]")
usr << output("[eye_collection]", "full_stats_grid:2,[grid]")
if(usr.a2 != "null")
usr << output("<font color = red>Bijuu Mastery", "full_stats_grid:1,[++grid]")
usr << output("<font color = red>[bijuu_uses]", "full_stats_grid:2,[grid]")
if(usr.clan == "Blood Thirsty" || usr.clan == "Ruthless")
usr << output("<font color = red>Rage", "full_stats_grid:1,[++grid]")
usr << output("<font color = red>[rage]", "full_stats_grid:2,[grid]")

usr << output("Age", "full_stats_grid:1,[++grid]")
usr << output("[round(age)]", "full_stats_grid:2,[grid]")

usr << output("Skillpoints", "full_stats_grid:1,[++grid]")
usr << output("[skillpoints] ", "full_stats_grid:2,[grid]")

usr << output("Attribute Points", "full_stats_grid:1,[++grid]")
usr << output("[levelpoints] ", "full_stats_grid:2,[grid]")

usr << output("[clan] Mastery", "full_stats_grid:1,[++grid]")
usr << output("Level [future_two] ", "full_stats_grid:2,[grid]")

if(!usr.client) return
spawn(50) if(usr && usr.client)client.updateBars()

winset(usr, "full_stats_grid2", "cells=2x[grid]")

while(blevel == level && body == experience && money == funds && factionpoints == faction_points && \
chakra == max_chakra && curchakra == max_chakra && stamina == max_stamina && curstamina == max_stamina && \
curwound == wounds && maxwound == max_wounds && \
str == str_ && strbuff == str_buff && strneg == str_debuff && \
con == con_ && conbuff == con_buff && conneg == con_debuff && \
rfx == rfx_ && rfxbuff == rfx_buff && rfxneg == rfx_debuff && \
int == int_ && intbuff == int_buff && intneg == int_debuff)

sleep(100)


if(stunned < 0)
stunned = 0
if(curstamina<0)
curstamina=0
if(curchakra<0)
curchakra=0
if(curwound<0)
curwound=0
if(stunned)
stunned-=0.2
if(stunned < 0)
stunned = 0

usr.statLoop_active = false

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.
This is awesome, great help. I really appreciate. I'll do these things and report the results. Thanks again.