Reduce quic::ConnectionId size from 24 bytes to 16 bytes on 64 bit system. This reduces some memory usage of connection & session on the server side. sizeof(GfeQuicServerSession) = 4080 -> 4032 sizeof(GfeQuicConnection) = 5968 -> 5880 PiperOrigin-RevId: 338718268 Change-Id: Ibce3233b9b9b6499021b95ef11eb75868388cb06
diff --git a/quic/core/quic_connection_id.cc b/quic/core/quic_connection_id.cc index a1c1439..57e57c5 100644 --- a/quic/core/quic_connection_id.cc +++ b/quic/core/quic_connection_id.cc
@@ -50,7 +50,12 @@ } // namespace -QuicConnectionId::QuicConnectionId() : QuicConnectionId(nullptr, 0) {} +QuicConnectionId::QuicConnectionId() : QuicConnectionId(nullptr, 0) { + static_assert(offsetof(QuicConnectionId, padding_) == + offsetof(QuicConnectionId, length_), + "bad offset"); + static_assert(sizeof(QuicConnectionId) <= 16, "bad size"); +} QuicConnectionId::QuicConnectionId(const char* data, uint8_t length) { length_ = length;
diff --git a/quic/core/quic_connection_id.h b/quic/core/quic_connection_id.h index 52d5e11..d3706c8 100644 --- a/quic/core/quic_connection_id.h +++ b/quic/core/quic_connection_id.h
@@ -99,7 +99,6 @@ bool operator<(const QuicConnectionId& v) const; private: - uint8_t length_; // length of the connection ID, in bytes. // The connection ID is represented in network byte order. union { // If the connection ID fits in |data_short_|, it is stored in the @@ -107,9 +106,16 @@ // Otherwise it is stored in |data_long_| which is guaranteed to have a size // equal to |length_|. // A value of 11 was chosen because our commonly used connection ID length - // is 8 and with the length, the class is padded to 12 bytes anyway. - char data_short_[11]; - char* data_long_; + // is 8 and with the length, the class is padded to at least 12 bytes + // anyway. + struct { + uint8_t padding_; // Match length_ field of the other union member. + char data_short_[11]; + }; + struct { + uint8_t length_; // length of the connection ID, in bytes. + char* data_long_; + }; }; };