244
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 ...
- 125k
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 ...
- 125k
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 ...
- 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 ...
- 115k
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 ...
- 395
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 ...
- 125k
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,...
- 845
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 (...
- 29.3k
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 ...
- 14.7k
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 ...
- 125k
13
votes
How to load a spherical planet and its regions?
As you've already shown, there are a number of solutions to this problem, but none 100% ideal. Spheres are tricky.
Cube-based
One common route, used by Spore and quite likely other games (though it'...
- 125k
13
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 ...
- 125k
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, ...
- 10.4k
11
votes
Accepted
In a 2D physics engine, how do I avoid useless collision resolutions when objects come to a rest?
I suspected OP already knew this approach so I mentioned it in a comment as just a starting point, but I'll try fleshing it out a bit more...
Most physics engines divide dynamic objects into two ...
- 125k
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 ...
- 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 ...
- 21.2k
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 ...
- 9,945
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 ...
- 413
9
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:
...
- 201
8
votes
How do I efficiently check if a point is inside a rotated rectangle?
Edit: The OPs comment has been skeptical about the efficiency of the suggested negative circular bound check to improve the algorithm in order do checks whether an arbitrary 2D point lies within a ...
- 823
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:
...
- 1,525
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 ...
- 16k
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 ...
- 16k
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 ...
- 125k
6
votes
Accepted
SerializeField vs GetComponent Efficiency
Use the inspector to allow the user (you, or other developers) to be able to easily define the Component themselves without having to modify your code.
Use the GetComponent() method if there is no ...
- 1,728
6
votes
Accepted
How to PRECISELY measure execution time of a code?
For the kind of micro-optimisation that you are trying to do, nothing will beat real-life usage patterns, with your algorithm embedded in a real program, consuming and producing real data. There are ...
- 14.8k
6
votes
Accepted
Efficiently Handling Entity-Interactions in a Tile-Based World
You have 3 major options:
1: Implement some kind of sorting or data structure.
For example: Keep monsters in a list/array (Something you are probably already doing) and sort them by ...
- 176
6
votes
Accepted
How can I speed up this HLSL shader?
I can't see anything fundamentally wrong with the shader, but here are a few things I find commonly done wrong with deferred shading that you might be doing.
1: Drawing full screen lights. The beauty ...
- 1,765
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 ...
- 8,284
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 ...
- 69
Only top scored, non community-wiki answers of a minimum length are eligible
Related Tags
optimization × 438unity × 94
performance × 59
c++ × 50
opengl × 45
c# × 36
2d × 26
collision-detection × 26
java × 24
rendering × 24
algorithm × 24
xna × 20
shaders × 18
android × 17
textures × 17
javascript × 16
3d × 15
path-finding × 13
frame-rate × 12
physics × 11
tiles × 11
gpu × 11
memory-efficiency × 11
graphics × 10
mobile × 10