ID:2708063
 
(See the best response by Ter13.)
Hey there!
Not a coding question per se, but I'm just curious as to how I can make my game less "laggy".
World CPU seems to be somewhat high (above 10) when this lag occurs, so it's most likely a coding problem.
Are there any tips on how to reduce lag in games, or how to view what's causing the lag?
Thanks!
This is kind of a broad question. A better place to start would be profiling your code. You can start the profiler and then observe what procs are running most often and how much time they take.
I guess what I'm asking is if there are any general tips or coding practices to avoid in order to keep your games performance high.
I'll also take a look at the profiler though, thanks!
In things that're called very often lets say 30 times a second, you want to cram as much logic into a single function and not multiple as the proc overhead adds up.

Probably the only issue with performance.
Best response
Only disagreement with koz, is on the metric. 30 times a second is ~1 time per frame. I would start cramming logic together in the thousands of times per second. Invocation overhead is not insignificant, but it really takes a lot to start stacking up.

In general, you want to reduce the amount of work you do to achieve any given result. This means maybe precaching data, or using log(n) rather than n or n^2 complexity where possible.

The other thing, is to distribute stuff over time as much as you can. If you don't need the data *right now*, allow it to be lazy about when the calculation finishes. Stuff like map loading / saving, pathfinding, and bulk object creation especially, distribute.

To start optimizing your project though, you really need to be more specific. There are clever ways to get around a lot of limitations, and sometimes it's just a matter of reducing your scope. Try to work toward the strengths of the system, rather than trying to make the system do exactly what you want how you want.