245 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
  • 134k
55 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 ...
DMGregory's user avatar
  • 134k
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
  • 119k
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
  • 134k
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
  • 890
23 votes
Accepted

How do Minecraft know where village's buildings are if the village is not generated yet?

Yes, it generates more chunks (or at least more of the village tree) than you think it does. This is what I call "area of interest" in my voxel code. There are two kinds of area of interest: Logical (...
Engineer's user avatar
  • 29.5k
18 votes
Accepted

How to reduce the time taken to path-find to an unreachable location?

Using a bidirectional path finder usually solves this issue if the area the player is stuck in is small. They basically advance from the player's position and the destination at the same time and when ...
Bálint's user avatar
  • 14.9k
18 votes
Accepted

How are NP-Hard problems managed in game development contexts?

In my experience, the main way NP-Hard problems are solved in game development involves relying on the fact that our instances tend to be quite small. We usually don't need to solve NP-Hard problems ...
DMGregory's user avatar
  • 134k
14 votes

How can City-sim simulate hundreds of characters?

Like so much of gamedev, the answer to how city sim games accomplish this seemingly-impossible feat is: they probably don't. They're just faking it well. ;) Sims like these will typically operate on a ...
DMGregory's user avatar
  • 134k
13 votes

How to reduce the time taken to path-find to an unreachable location?

You should make a sort of connectivity map - by flood-filling all unconnected walkable areas and marking each one with a different tag, once at game start (and every time when terrain changes). Then, ...
Kromster's user avatar
  • 10.6k
10 votes
Accepted

How to make illusion of round world?

You can do this purely in a vertex shader. You'd want to apply this shader to everything you render. One trick though that you can do is weight it so that the nearby objects are flat out to say 100 ...
Sirisian's user avatar
  • 584
10 votes

How to optimize collisions

Query only nearby objects As you already know, you need to check only nearby objects. This means that you need a way to retrieve a list of nearby objects to check. To do that, you need to divide the ...
Theraot's user avatar
  • 26.6k
10 votes

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

When in doubt, use best practices. You are in doubt. That was the easy answer. Reality is more complex, of course. First, there's the myth that game programming is ultra super high performance ...
Peter's user avatar
  • 9,925
10 votes

How do Minecraft know where village's buildings are if the village is not generated yet?

Technical stuff During Minecraft's chunk generation a chunk passes several stages before it is done and can be rendered. These stages, in order, are as follows: ...
hoffmale's user avatar
  • 211
9 votes

Why is it so bad to optimize too early?

A lot of the answers seem to be focusing a lot on the performance aspect of "optimization" while I myself like to look at optimization and the whole ordeal of optimizing too early at a more abstract ...
Ceiling Gecko's user avatar
8 votes
Accepted

Possible to yield a coroutine when it is taking too long to run?

You can use Time.realtimeSinceStartup as reference for the time passed: ...
Leo's user avatar
  • 1,585
8 votes

Why is it so bad to optimize too early?

Money. It comes down to that. Money. Since time is money*, the more time you spend on activities that are not guaranteed to generate more money (i.e. you can't consider these activities as ...
Vaillancourt's user avatar
  • 16.3k
7 votes
Accepted

C++ Object management/deletion

You're using a std::vector<Bullet>. This has the advantage of keeping data contiguous in memory, so iterating over it is fast (it has something to do with ...
Vaillancourt's user avatar
  • 16.3k
7 votes

Is there a difference between using one large mesh with 100k polygons and using 1000 meshes with 100 polygons each?

There are two main components to the time it takes to process a draw call: The time it takes to calculate all the results for every work item in the batch The time it takes to upload info / switch ...
DMGregory's user avatar
  • 134k
6 votes

Add and remove tiles? Or better to have them all loaded off screen?

In a case like this, you are going to want to Pool your world tiles. The idea is to pre-load a fixed amount of tiles that you will be re-using during the rendering of your world. When setting a ...
jgallant's user avatar
  • 8,414
6 votes

Why is it so bad to optimize too early?

Optimization is, by definition, the process of increasing the efficiency of a solution up to the point where it looses its efficacy. This process implies then a reduction of the solution's space. At ...
Earendel's user avatar
6 votes
Accepted

Is it possible to calculate a direction vector without sqrt?

If you want a correct mathematical result (correctly rounded to within floating point precision), a square root is the way to go. It's true that it's more expensive than a multiply, but it's still ...
DMGregory's user avatar
  • 134k
6 votes

Should I model with quads or with n-gons?

It doesn't really matter. 3d models with faces that have more than 3 vertices don't really exist in 3d graphics*. They are a usability-convention of the modeling program. 3d rendering engines can only ...
Philipp's user avatar
  • 119k
5 votes
Accepted

How can I improve my rendering performance in Java?

First of all, instead of relying on the ideas of people, who didn't see a single line of code or even a picture of your game, try profiling it, finding the bottleneck and removing it. If that isn't ...
Bálint's user avatar
  • 14.9k
5 votes

Avoid useless copies of buffers

The answer is using a PBO, Pixel Buffer Object. You map a opengl buffer and put the image data into there. Then unmap and bind that buffer to GL_PIXEL_UNPACK_BUFFER...
ratchet freak's user avatar
5 votes
Accepted

Do empty Update() methods get executed and slow down the game while playing?

As stated in the Unity Blog post 1000 Update Calls: [If you have empty MonoBehaviour messages], all these methods will be called each frame for all your scripts, mostly doing nothing at all! One ...
DMGregory's user avatar
  • 134k
5 votes
Accepted

Factorio style conveyer belts, how to implement multiple speeds?

Apply the optimization to sequences of belts of the same speed only. When items reach a belt of a different speed, they leave that belt section and enter a different belt section, just like if they ...
Kevin Reid's user avatar
  • 5,498
5 votes
Accepted

How does Godot 4 copy vectors?

Checking the GDScript reference docs: Built-in types Built-in types are stack-allocated. They are passed as values. This means a copy is created on each assignment or when passing them as arguments ...
DMGregory's user avatar
  • 134k
4 votes
Accepted

Why create meshes instead of using Planes?

First of all if you are interested in generating meshes I recommend to you this series of articles in gamasutra about procedural meshes Modelling by numbers So returning to the main question, ...
Santiago murillo's user avatar

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