up-device-battery: align structure UpBatteryInfo for 64-bit

Reduces size struct 120 bytes -> 104 bytes

This commit will decrease costs copying, moving, and creating object-structures only for common 64bit processors due to the 8-byte data alignment.
Smaller size structure or class, higher chance putting into CPU cache. Most processors are already 64 bit, so the change won't make it any worse.
I noticed unaligned structs when analyzing the memory layout CPU cache using utilities Cachegrind and Pahole (Red Hat tool).

Example ideal align strutures in mem layout:

- https://www.phoronix.com/news/Linux-6.8-Networking
- https://lore.kernel.org/netdev/20231129072756.3684495-1-lixiaoyan@google.com/

References about technique:

- https://hpc.rz.rptu.de/Tutorials/AVX/alignment.shtml
- https://wr.informatik.uni-hamburg.de/_media/teaching/wintersemester_2013_2014/epc-14-haase-svenhendrik-alignmentinc-presentation.pdf
- https://en.wikipedia.org/wiki/Data_structure_alignment
- https://stackoverflow.com/a/20882083
- https://zijishi.xyz/post/optimization-technique/learning-to-use-data-alignment/
This commit is contained in:
Herman Semenoff 2026-04-30 03:59:27 +03:00
parent 25303ba527
commit 671679ce63

View file

@ -68,12 +68,12 @@ typedef struct {
} UpBatteryValues;
typedef struct {
gboolean present;
const char *vendor;
const char *model;
const char *serial;
gboolean present;
UpBatteryUnits units;
union {
@ -87,8 +87,8 @@ typedef struct {
} charge;
};
UpDeviceTechnology technology;
gdouble voltage_design;
UpDeviceTechnology technology;
gint charge_cycles;
gdouble voltage_max_design;
gdouble voltage_min_design;