Premature Optimizations.....

preview_player
Показать описание
#cpp #programming

Similar video From Gabes With Gabe on performance lies: 🤯

Why switch is as fast as if: 🙀

Join my Discord:

Check out my Steam Game Midnight Arrow: 🚂

Join this channel if you want to support me 😻:

Credits:

Рекомендации по теме
Комментарии
Автор

i wish to not many people see this comment

mckzik
Автор

Golden rule of optimization, or software development even, is: "Solve problems which you have, instead of problems you might have"

TryboBike
Автор

Ok, but also find guy with slow old laptop, and make sure that game is also fast enough on his laptop with limited resources, and if is not, then you should try to optimize

GhostVlVin
Автор

I'm optimizing RIGHT NOW and there's nothing you can do about it! 😏

Jeremyak
Автор

you're like a father to me at this point with your amount of actual handy advice as more or less a noob

moody_weirdo
Автор

The first example you show isn't an optimization that "ended up being slower"... It's a bug that surprisingly didn't crash the program lol. It's slower because it's checking past the end of the array into what is now other data, but still treating it as the previous type....

Hazanko
Автор

I prematurely optimize not to achieve better performance, but because that's my default coding style. Example:
- constexpr when possible;
- allocate objects on stack when possible;
- prefer std:array over std::vector and std::vector over other containers, unless container is large and elements needs to be removed from begin/middle;
- reuse heap allocated objects when possible; e.g. network read/write buffer;
- one line member functions define in it's class definition, so it would be inlined;
- large objects or objects who allocates memory on heap internally, pass around as const &/*;
- RVO/NRVO;
- if needed to loop over large amount of data, maybe use struct of arrays (SOA) instead of array of structs (AOS);
- avoid interfaces when possible;

Of course i would not sacrifice code readability for questionable performance gains.

edmundas
Автор

Bro, your minecraft clone is beautiful.

kgola
Автор

I would definitely agree that performance is not the cause for concern with that crafting system. In my eyes, it's how time consuming and error prone manually entering all the different variants of a single recipe will get.

shrootskyi
Автор

THIS!
Thank you, I always begin to optimize my code before it's even done and working, it happens against my will and have to stop myself every time

mementomori
Автор

This is the most convoluted rust w I ever heard

mintx
Автор

For me it’s you should optimise things that are called very very often like multiple times per second
As for the other part of code being called way less often just make sure it works forget optimise.
once the project it’s finished you can start doing more heavier optimisation

dad
Автор

One time I refactored all my code base by replacing every i++ with ++i

leshommesdupilly
Автор

I'm glad you included the first type and the third type for contrast. Some early structural choices can limit later options, important operations in a game may be very latency sensitive but low throughput, versus some program that does scientific number crunching which is not affected by latency but requires high throughput per joule.

Even selecting the language can be considered an initial optimization yet could not be considered premature. Language selection could also be in the pessimization category, if you start with a slow highly abstracted language then writing the prototype code may be much faster and have fewer obvious bugs, but eventually you may have complications when optimizing.

mytech
Автор

If Jonathan Blow saw this video he would be mad

sbvtiyq
Автор

A few years back I got back into some game development for the first time in 30 years.
I was amazed at how inefficient for example Unity and Godot actually are as frame works, but PCs became perhaps 4000x faster in the 34 years since i programmed my last game on a Atari ST 68000 8MHz parts I had even written in assembly to keep the speed.

It almost feels freeing to make a side scroller shmup and just do everything in the game loop without trickery :D Especially when I used Zig and Raylib, no added game engine overhead. 1200+ fps on a Mac Book m1 :D It's insanely fast without "optimisation"
Although I have an innate urge to optimise especially for memory usage, that comes as second nature to me. Having programmed my first game on a 3KB VIC20 :D But it's trivial to have a well performing 2D game these days.

CallousCoder
Автор

Insulating newbies from the idea that optimization is important will let them form bad habits that will hard to break

Oaisus
Автор

Yes, but I decided to simply pull out a pointer variable declaration from a loop into the parent scope and suddenly it’s 12% faster, even with -O3 and vectorization enabled. This loop had a nested loop, and I was executing 7, 998, 000 2D AABB collision checks every run, and I had such things like ‘__restrict’ on my pointers. I thought it was a fluke so I retested several times, and then I reordered the tests to run the slow one first and the fast one second, yet the result was the same. I was using Clang 16.0.5 at the time.

nicholastheninth
Автор

You should also talk about FPS. People very often ignore improvements like 10 from 11 FPS (90ms difference), but panic when uncapped game goes from 600 to 500 (0.3 ms difference). And other common problems like running all logic every frame along rendering, not using tools like Nvidia Insight to see what is actually going haywire under the hood via frame debugger, and not resetting chrono properly (start value taken right before while loop, end value including cost of outputting all debug info), etc

StriderPulse
Автор

This is why planning is key. If the plan calls for only 3 items, there’s no point making some generic optimised inventory system that can support a million items and run in O(1) time

BudgiePanic