r/cpp • • Mar 07 '24

What are common mistakes in C++ code that results in huge performance penalties?

As title, list some common mistakes that you have done/seen which lead to performance penalties.

235 Upvotes

325 comments sorted by

View all comments

Show parent comment

4

u/tonyarkles Mar 07 '24

I don’t remember which MCU it was… probably an STM32F042 or F103 that required an extra instruction cycle in between writing two peripheral registers. Worked fine in debug mode… that was a special day.

4

u/garfgon Mar 07 '24

Which I'm sure was explained clear as day in the 700 page user guide (/s).

3

u/SkoomaDentist Antimodern C++, Embedded, Audio Mar 07 '24

That's quite literally why the __DSB() intrinsic exists on ARM platforms.

2

u/tonyarkles Mar 07 '24

That was the day I learned about it!