[clang] [Clang][analyzer] add documentation for optin performance padding (padding checker) #73675 (PR #86411)
via cfe-commits
cfe-commits at lists.llvm.org
Wed Mar 27 04:46:28 PDT 2024
================
@@ -804,10 +804,88 @@ 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 thus decreased performance by reducing the effectiveness of the
+processor cache. Padding bytes are added by compilers to align data accesses
+as some processors require data to be aligned to certain boundaries. On others,
+unaligned data access are possible, but impose significantly larger latencies.
+
+To avoid padding bytes, the fields of a struct should be ordered by decreasing
+by alignment. Usually, its easier to think of the ``sizeof`` of the fields, and
+ordering the fields by ``sizeof`` would usually also lead to the same optimal
+layout.
+
+In rare cases, one can use the ``#pragma pack(1)`` directive to enforce a packed
+layout too, but it is discouraged and the reordering of fields should be
+preferred.
----------------
NagyDonat wrote:
```suggestion
In rare cases, one can use the ``#pragma pack(1)`` directive to enforce a packed
layout too, but it can significantly increase the access times, so reordering the
fields is usually a better solution.
```
https://github.com/llvm/llvm-project/pull/86411
More information about the cfe-commits
mailing list