devlog
1 min read

Shipping scripts that run at 0.00ms idle

FiveMPerformanceLua

Every script on trase.dev sits at 0.00ms idle. I don't ship one until it does. It's the number I care about most, so I want to explain why, and how I actually get there.

Most people watch the wrong number. They open the resource monitor and panic about the spike when a script does something. That spike is fine. The one that actually hurts your server is idle cost, what a resource burns while nothing is even happening. It's tiny on its own, but it never stops running, and it stacks across every script you've got.

One script idling at 0.02ms sounds like nothing. Run 40 of them on a full server and now you've got lag nobody can track down.

Getting to zero mostly comes down to a few habits:

  • Don't run loops that just sit there waiting for something. If a thread only exists to watch for a change, use an event instead.
  • Bail out early. The first thing a function that runs a lot should do is the cheapest check that lets it stop.
  • Cache the expensive stuff. Natives and table lookups in a hot path get done once, not every tick.
  • Actually profile it. resmon open, server sitting idle, watch the number. If it's not 0.00, it's not done.

None of this is complicated. If you write it with performance in mind from the start, you're not going back to fix it later. That's just how I build everything on here.

Want the next one in your inbox?

I post when I've got something worth reading. Drop your email and I'll send it over.