Daniel Lemire compares two ways to write the default constructor for a C++ struct with two pointers and a length. The choice changes what span{} does. In his test it also changes the code GCC generates for a hot loop, even though the empty value is used only on exit.
- With
span() = defaulton its first declaration,span{}zero-initializes the object. Withspan() {}, the user-provided constructor leaves the fields uninitialized in this struct. - GCC 16 writes all three fields straight to their destination with the empty constructor. With
= default, it writes two fields into a temporary and copies them back. - The defaulted version takes 8.04 nanoseconds per span on GCC 16.2 versus 1.73 for the empty constructor. GCC 15.2 shows a similar gap; GCC 14.3 and Clang 21 come in near 1.7 for both.
Keep the initialization behavior your callers expect. If a compiler upgrade slows a tight loop, compare the assembly around the whole loop, including the branch you expect to be cheap.