From d604a80097fee5405de84f4ec65e4aa1b3c0844c Mon Sep 17 00:00:00 2001 From: Mathias Gibbens Date: Mon, 18 Aug 2025 13:02:11 +0000 Subject: [PATCH] Place fields used in atomic operations at beginning of struct Signed-off-by: Mathias Gibbens --- errors.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/errors.go b/errors.go index 4f6509d..5158ae3 100644 --- a/errors.go +++ b/errors.go @@ -95,6 +95,10 @@ type contextItem struct { // context, cause, and metadata like code and category. It is thread-safe and // supports pooling for performance. type Error struct { + // Fields used in atomic operations. Place them at the beginning of the + // struct to ensure proper alignment across all architectures. + count uint64 // Occurrence count for tracking frequency. + // Primary fields (frequently accessed). msg string // The error message displayed by Error(). name string // The error name or type (e.g., "AuthError"). @@ -103,7 +107,6 @@ type Error struct { // Secondary metadata. template string // Fallback message template if msg is empty. category string // Error category (e.g., "network"). - count uint64 // Occurrence count for tracking frequency. code int32 // HTTP-like status code (e.g., 400, 500). smallCount int32 // Number of items in smallContext.