246 votes
Accepted

Why is it so bad to optimize too early?

Preamble: A few objections have been raised in the comments, and I think they largely stem from a misunderstanding of what we mean when we say "premature optimization" - so I wanted to add a little ...
user avatar
  • 115k
155 votes

How can I clean up excessive player-created rubble?

Figure out your bottleneck A few hundred moving objects should not be a problem. However, a few hundred colliding objects might be. It will take some testing, yet I believe the bottleneck you have ...
user avatar
  • 18.9k
89 votes
Accepted

When is the best time to consider performance?

Engineering for Performance Follow vendor recommendations. Use the correct data structures. Implement the correct usage patterns. Don't do anything stupid. Optimization When already written code is ...
user avatar
80 votes
Accepted

How do bullets work in video games?

I can certainly see why you would think that it would be hard to simulate those, but there are enough constraints on bullets (all projectiles, really) to make them easier. They are generally ...
user avatar
  • 1,299
71 votes
Accepted

How can I clean up excessive player-created rubble?

First of all, that game mechanic looks like it could be super fun, so congrats on thinking of it! Here are two simple solutions that could be used independently or together to solve this particular ...
user avatar
58 votes

Intentionally using "worse machines" to develop a game?

Intentionally doing everything on a weak PC when a stronger one is available to you is just masochism. Developers run lots of tools in parallel to the game which require resources, and also do various ...
user avatar
  • 112k
54 votes
Accepted

Optimization of rendering of cube world

No high-performance voxel renderer draws individual cubes or cube faces. To get good performance, groups of voxels are assembled together into a single mesh, called a "Chunk". A chunk is typically ...
user avatar
  • 115k
49 votes
Accepted

How to handle a large number of pickups in a MMO game

By simply only loading those parts of the world into memory which are close to the player. Anything else is suspended to hard drive. When there is a tiny object laying around two kilometers away, then ...
user avatar
  • 112k
47 votes
Accepted

How can I make A* finish faster when the destination is impassable?

Some ideas on avoiding searches that result in failed paths altogether: Island ID One of the cheapest ways to effectively finish A* searches faster is to do no searches at all. If the areas are ...
user avatar
  • 3,022
45 votes

How do bullets work in video games?

Probably one of the most efficient ways to implement bullets is using what is known as hitscan. It is rather simple in its implementation - when you fire, you check to see what the gun is aiming at (...
user avatar
  • 1,388
44 votes

How can I reduce the performance impact of rendering trees?

There are couple of things you can do to increase drawing performance. You said they were pretty far away. You could use LOD to decrease the vertex count of those trees, and thus decreasing time ...
user avatar
  • 3,182
44 votes

Why is it so bad to optimize too early?

note: this answer began as a comment on DMGregory's answer, and so doesn't duplicate the very good points he makes. "Would it not be incredibly difficult to change some of the core structures of the ...
user avatar
  • 814
44 votes

Is the Microsoft recommendation to use C# properties applicable to game development?

But my impression is that in game development, unless you have a reason to do otherwise, everything should be nearly as fast as possible. Not necessarily. Just like in application software, there is ...
user avatar
  • 112k
42 votes
Accepted

Is it normal for a game to use 100% CPU?

Yes, this is normal for a real-time game to try to use 100% CPU to perform as fast and good as it can. So that player sees as much frames per second or as good physics simulation or anything else as ...
user avatar
  • 10.1k
34 votes
Accepted

Is there any harm in having the main game loop run uncontrolled?

It will cause one CPU core to always run on 100%. This usually doesn't cause any harm to the system. CPUs are designed to run on 100% for hours. But on a mobile device it will drain the battery ...
user avatar
  • 112k
34 votes
Accepted

Improving an O(N^2) function (all entities iterating over all other entities)

I know you do not conceptualize this as collisions, however what you are doing is colliding a circle centered at the creature, with all food. You really do not want to check food that you know is ...
user avatar
  • 18.9k
32 votes
Accepted

How can I efficiently load huge volumes of star systems?

The trick Elite likely uses is that they don't pre-generate the whole galaxy and store it in a database. They likely generate most of the galaxy at runtime when it is needed. I would do this using a ...
user avatar
  • 112k
28 votes
Accepted

Which opcodes are faster at the CPU level?

Agner Fog's optimization guides are excellent. He has guides, tables of instruction timings, and docs on the microarchitecture of all recent x86 CPU designs (going back as far as Intel Pentium). See ...
user avatar
26 votes

How can I shorten the length of time spent on finding a path using my A* pathfinding code?

Let's start with some general C# optimization advice: Avoid heap allocations in your hot path. That means anywhere you have new Foo(...) where ...
user avatar
  • 115k
25 votes

How can I make A* finish faster when the destination is impassable?

AStar is a complete planning algorithm, meaning if there exists a path to the node, AStar is guaranteed to find it. Consequently, it must check every path out of the start node before it can decide ...
user avatar
  • 3,567
25 votes

Why is it so bad to optimize too early?

"Do not optimise early" doesn't mean "pick the worst possible way to do things". You still need to consider performance implications (unless you're just prototyping). The point is not to cripple other,...
user avatar
  • 845
22 votes

When is the best time to consider performance?

If you want to do optimization at the right times, have slow machines and use them. For a small shop, a good option is to use a slow laptop on the commute and a fast desktop in the office. As an ...
user avatar
  • 9,937
22 votes

How to handle a large number of pickups in a MMO game

You have two very different things to manage: The server must manage the entire world, in an authorative manner. For that, communication with N clients (where N is "massive") is necessary. The client ...
user avatar
  • 1,364
22 votes
Accepted

Why does Unity use reflection to get the update method?

It doesn't How Update is called No, Unity doesn’t use System.Reflection to find a magic method every time it needs to call one. Instead, the first time a MonoBehaviour of a given type is accessed the ...
user avatar
21 votes

How can I make A* finish faster when the destination is impassable?

Run a dual A* search from the target node in reverse as well at the same time in the same loop and abort both searches as soon as one is found unsolvable If the target has only 6 tiles accessible ...
user avatar
18 votes
Accepted

Is * calling *= (or *= calling *) slower than writing seperate functions (for math library)?

In practice, no additional overhead will be incurred. In C++, small functions are usually inlined by the compiler as an optimization, so the resulting assembly will have all the operations at the ...
user avatar
16 votes
Accepted

Most efficient way to convert Vector3 to Vector2

Vector3 v3 = Vector3.one; Vector2 v2 = v3; Vector3s can be implicitly converted to Vector2 (z is discarded). http://docs.unity3d.com/ScriptReference/Vector2-...
user avatar
  • 730
16 votes

Improving an O(N^2) function (all entities iterating over all other entities)

You should adopt a space partitioning algorithm like BVH to reduce complexity. To be specific to your case, you need to make a tree that consists of axis-aligned bounding boxes that contain food ...
user avatar
  • 1,404
15 votes
Accepted

3D models budget. What matters more number of triangles or vertices

Let's imagine a big grid mesh, like one we might use for terrain. We'll render n triangles worth of it, covering say half our 1080p screen, in a single draw call. ...
user avatar
  • 115k
14 votes
Accepted

Why is the for loop more efficient than the for each loop in Unity?

A foreach loop ostensibly creates an IEnumerator object out of the collection you pass it, and then walks over that. So a loop like this: ...
user avatar
  • 115k

Only top scored, non community-wiki answers of a minimum length are eligible