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 ...
DMGregory's user avatar
  • 132k
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 ...
Theraot's user avatar
  • 25.2k
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 ...
Maximus Minimus's 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 ...
Tom K's user avatar
  • 1,319
72 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 ...
Chase Sandmann's 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 ...
Philipp's user avatar
  • 118k
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 ...
DMGregory's user avatar
  • 132k
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 ...
Philipp's user avatar
  • 118k
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 (...
Seta's user avatar
  • 1,398
45 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 ...
Lasse's user avatar
  • 3,241
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 ...
Baldrickk's 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 ...
Philipp's user avatar
  • 118k
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 ...
Kromster's user avatar
  • 10.6k
40 votes
Accepted

Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)

TLDR: Get DirectBitmap from https://stackoverflow.com/a/34801225 and add ...
PTwr's user avatar
  • 516
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 ...
Theraot's user avatar
  • 25.2k
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 ...
Philipp's user avatar
  • 118k
28 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 ...
DMGregory's user avatar
  • 132k
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,...
Luaan's user avatar
  • 845
23 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 ...
Draco18s no longer trusts SE's user avatar
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 ...
Peter's user avatar
  • 9,955
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 ...
Damon's user avatar
  • 1,374
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 ...
Slipp D. Thompson's user avatar
17 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-...
Mattias's user avatar
  • 750
17 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. ...
DMGregory's user avatar
  • 132k
17 votes

Game loop isn't performing well enough, so my frame rate is too low (Windows Form + GDI+)

When things bog down, check your inner loop. That's the code being run the most often, so even a small inefficiency there stacks up. Here we see: ...
DMGregory's user avatar
  • 132k
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 ...
Ocelot's user avatar
  • 1,423
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: ...
DMGregory's user avatar
  • 132k
13 votes
Accepted

How can I reduce the performance impact of rendering trees?

Ok, so the problem was simply that I wasn't using pre-computed realtime GI. I check that on a little while ago but it didn't have an immediate effect so I left it and forgot about it, and the lighting ...
mr-matt's user avatar
  • 2,759
12 votes

Performance degrading when resolution increases for a 4k screen

One way to limit the resolution of your game is to have your camera render to a RenderTexture. You can create a RenderTexture in script to match the current aspect ratio of your window/screen, or even ...
DMGregory's user avatar
  • 132k
12 votes

Can I just convert everything in godot to C#

The Godot C# documentation provides an incomplete list of the API differences between C# and GDScript. There are some difference in the methods & properties names. Additionally, some things in C# ...
Pikalek's user avatar
  • 11.6k

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