================
@@ -804,10 +804,38 @@ Check for performance anti-patterns when using Grand 
Central Dispatch.
 
 .. _optin-performance-Padding:
 
-optin.performance.Padding
-"""""""""""""""""""""""""
+optin.performance.Padding (C, C++, ObjC)
+""""""""""""""""""""""""""""""""""""""""
 Check for excessively padded structs.
 
+This checker detects structs with excessive padding, which can lead to wasted 
memory and decreased performance. Padding bytes are added by compilers to align 
data within the struct for performance optimization or memory alignment 
purposes. However, excessive padding can significantly increase the size of the 
struct without adding useful data, leading to inefficient memory usage, cache 
misses, and decreased performance.
+
+.. code-block:: c
+
+   #include <stdio.h>
+   // #pragma pack(1) // Uncomment it to disable structure padding
+   struct TestStruct {
----------------
steakhal wrote:

My problem with this `TestStruct` is that there is no way you could get rid of 
the two bytes padding using standard C++.

Maybe a better example would be if one could reorder the fields to actually 
benefit from the better layout.
As a rule of thump people should sort fields decreasing by alignment (or 
sizeof) to achieve the best layout. (maybe this technique could be also 
mentioned in the docs).

Lastly, this code example does not raise an issue of this checker, so it would 
be better to showcase a bug that we actually report.

Aside from that, we could also have a `OptimalStruct` that applies the 
technique I mentioned and demonstrates that the issue goes away.

https://github.com/llvm/llvm-project/pull/86411
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to