]> git.ipfire.org Git - thirdparty/bind9.git/commitdiff
shrunk cfgobj down from 48 bytes to 40 bytes
authorColin Vidal <colin@isc.org>
Fri, 5 Dec 2025 21:02:36 +0000 (22:02 +0100)
committerColin Vidal <colin@isc.org>
Sat, 6 Dec 2025 07:51:23 +0000 (08:51 +0100)
Follow-up of 38ce2906 as the size of the `cfg_obj_t` can actually goes
down to 40 bytes "for free", by using bitfields to only use 31 bits for
the `line` field, so the remaining bit can be use to hold the `cloned`
state without paying the extra 8 bytes padding.

lib/isccfg/include/isccfg/grammar.h
lib/isccfg/parser.c

index 6d1ef1e503c36e346ef1455abe9b78aa195fb070..9ad371b7e06065141ed40c2779f12fc83f26eb37 100644 (file)
@@ -206,9 +206,20 @@ struct cfg_obj {
         * These two 4 byte fields are contiguous to avoid an extra
         * padding of 4 bytes each, avoiding an extra 8 bytes in the
         * struct.
+        *
+        * `line` is 31 bits long (~2,000,000,000 is likely enough lines in a
+        * named config) so the `cloned` boolean fit in the extra bit, and won't
+        * take extra 8 bits because of padding.
         */
        unsigned int magic;
-       unsigned int line;
+       unsigned int line : 31;
+
+       /*%
+        * Indicates that an object was cloned from the defaults
+        * or otherwise generated during the configuration merge
+        * process.
+        */
+       bool cloned : 1;
 
        isc_refcount_t    references;
        cfg_obj_t        *file; /*%< separate string with its own refcount */
@@ -226,13 +237,6 @@ struct cfg_obj {
                cfg_netprefix_t   *netprefix;
                isccfg_duration_t *duration;
        } value;
-
-       /*%
-        * Indicates that an object was cloned from the defaults
-        * or otherwise generated during the configuration merge
-        * process.
-        */
-       bool cloned;
 };
 
 /*% A list element. */
index e7980be9cd3a957ad82d3a522f86024b293c1dd0..83722cb858f4827ead7c5952086fdcd076b6c626 100644 (file)
@@ -73,8 +73,8 @@
  * can take a significant amount of memory. This assert ensures that we
  * won't increase its size by mistake without getting a warning.
  */
-static_assert(sizeof(struct cfg_obj) <= 48,
-             "sizeof(cfg_obj_t) must be 48 bytes");
+static_assert(sizeof(struct cfg_obj) <= 40,
+             "sizeof(cfg_obj_t) must be 40 bytes");
 
 /* Shorthand */
 #define CAT CFG_LOGCATEGORY_CONFIG