Why init a string to "" vs default constructor?

Question:

Why is return ""; faster than return {}; when initializing an empty std::string container?

To test this, I compiled the following code:

#include <string>

std::string make_default() {
    return {};
}

std::string make_empty() {
    return "";
}

The compiled code (using clang 16 and libc++) is as follows:

make_default():
        mov     rax, rdi
        xorps   xmm0, xmm0
        movups  xmmword ptr [rdi], xmm0
        mov     qword ptr [rdi + 16], 0
        ret
make_empty():
        mov     rax, rdi
        mov     word ptr [rdi], 0
        ret

See live example at Compiler Explorer.

Notice how return {}; is zeroing 24 bytes in total, but return ""; is only zeroing 2 bytes.

Question: Why is return ""; faster than return {}; when initializing an empty std::string container?

The reason return ""; is faster than return {}; when initializing an empty std::string container is because return ""; only zeros out 2 bytes, while return {}; zeros out 24 bytes.

In the compiled code, return ""; simply sets the first two bytes of the std::string object to zero using the mov instruction. This is a single operation and is faster.

On the other hand, return {}; initializes the std::string object by zeroing out 24 bytes in total. It uses the xorps and movups instructions to zero out the bytes. This requires multiple instructions and is slower compared to return "";.

Therefore, return ""; is faster because it requires fewer operations to initialize the empty std::string container.