Optimize TransportParameters memory layout This CL reorders fields of TransportParameters, bringing the size from 1008 to 984 for a savings of 24 bytes. PiperOrigin-RevId: 839381192
diff --git a/quiche/quic/core/crypto/transport_parameters.cc b/quiche/quic/core/crypto/transport_parameters.cc index 3f4a3b6..9b38cb3 100644 --- a/quiche/quic/core/crypto/transport_parameters.cc +++ b/quiche/quic/core/crypto/transport_parameters.cc
@@ -18,10 +18,12 @@ #include "absl/strings/string_view.h" #include "openssl/digest.h" #include "openssl/sha.h" +#include "quiche/quic/core/crypto/quic_random.h" #include "quiche/quic/core/quic_connection_id.h" #include "quiche/quic/core/quic_constants.h" #include "quiche/quic/core/quic_data_reader.h" #include "quiche/quic/core/quic_data_writer.h" +#include "quiche/quic/core/quic_tag.h" #include "quiche/quic/core/quic_types.h" #include "quiche/quic/core/quic_utils.h" #include "quiche/quic/core/quic_versions.h" @@ -29,6 +31,8 @@ #include "quiche/quic/platform/api/quic_flag_utils.h" #include "quiche/quic/platform/api/quic_flags.h" #include "quiche/quic/platform/api/quic_ip_address.h" +#include "quiche/quic/platform/api/quic_logging.h" +#include "quiche/quic/platform/api/quic_socket_address.h" #include "quiche/common/platform/api/quiche_logging.h" #include "quiche/common/quiche_data_writer.h" #include "quiche/common/quiche_endian.h" @@ -548,14 +552,14 @@ kMaxAckDelayExponentTransportParam), max_ack_delay(kMaxAckDelay, kDefaultMaxAckDelayTransportParam, 0, kMaxMaxAckDelayTransportParam), - disable_active_migration(false), active_connection_id_limit(kActiveConnectionIdLimit, kDefaultActiveConnectionIdLimitTransportParam, kMinActiveConnectionIdLimitTransportParam, quiche::kVarInt62MaxValue), max_datagram_frame_size(kMaxDatagramFrameSize), - reliable_stream_reset(false), - initial_round_trip_time_us(kInitialRoundTripTime) + initial_round_trip_time_us(kInitialRoundTripTime), + disable_active_migration(false), + reliable_stream_reset(false) // Important note: any new transport parameters must be added // to TransportParameters::AreValid, SerializeTransportParameters and // ParseTransportParameters, TransportParameters's custom copy constructor, the @@ -563,8 +567,7 @@ {} TransportParameters::TransportParameters(const TransportParameters& other) - : perspective(other.perspective), - legacy_version_information(other.legacy_version_information), + : legacy_version_information(other.legacy_version_information), version_information(other.version_information), original_destination_connection_id( other.original_destination_connection_id), @@ -582,15 +585,16 @@ ack_delay_exponent(other.ack_delay_exponent), max_ack_delay(other.max_ack_delay), min_ack_delay_us_draft10(other.min_ack_delay_us_draft10), - disable_active_migration(other.disable_active_migration), active_connection_id_limit(other.active_connection_id_limit), initial_source_connection_id(other.initial_source_connection_id), retry_source_connection_id(other.retry_source_connection_id), max_datagram_frame_size(other.max_datagram_frame_size), - reliable_stream_reset(other.reliable_stream_reset), initial_round_trip_time_us(other.initial_round_trip_time_us), - discard_length(other.discard_length), google_handshake_message(other.google_handshake_message), + discard_length(other.discard_length), + perspective(other.perspective), + disable_active_migration(other.disable_active_migration), + reliable_stream_reset(other.reliable_stream_reset), debugging_sni(other.debugging_sni), google_connection_options(other.google_connection_options), custom_parameters(other.custom_parameters) {
diff --git a/quiche/quic/core/crypto/transport_parameters.h b/quiche/quic/core/crypto/transport_parameters.h index 027d73e..e716f6f 100644 --- a/quiche/quic/core/crypto/transport_parameters.h +++ b/quiche/quic/core/crypto/transport_parameters.h
@@ -5,13 +5,15 @@ #ifndef QUICHE_QUIC_CORE_CRYPTO_TRANSPORT_PARAMETERS_H_ #define QUICHE_QUIC_CORE_CRYPTO_TRANSPORT_PARAMETERS_H_ +#include <cstddef> #include <cstdint> #include <memory> #include <optional> +#include <ostream> +#include <string> #include <vector> #include "absl/container/flat_hash_map.h" -#include "absl/strings/string_view.h" #include "quiche/quic/core/quic_connection_id.h" #include "quiche/quic/core/quic_data_reader.h" #include "quiche/quic/core/quic_data_writer.h" @@ -19,6 +21,7 @@ #include "quiche/quic/core/quic_types.h" #include "quiche/quic/core/quic_versions.h" #include "quiche/quic/platform/api/quic_socket_address.h" +#include "quiche/common/platform/api/quiche_export.h" namespace quic { @@ -170,11 +173,16 @@ bool operator==(const TransportParameters& rhs) const; bool operator!=(const TransportParameters& rhs) const; - // Represents the sender of the transport parameters. When |perspective| is - // Perspective::IS_CLIENT, this struct is being used in the client_hello - // handshake message; when it is Perspective::IS_SERVER, it is being used in - // the encrypted_extensions handshake message. - Perspective perspective; + // Validates whether transport parameters are valid according to + // the specification. If the transport parameters are not valid, this method + // will write a human-readable error message to |error_details|. + bool AreValid(std::string* error_details) const; + + // Allows easily logging transport parameters. + std::string ToString() const; + + friend QUICHE_EXPORT std::ostream& operator<<( + std::ostream& os, const TransportParameters& params); // Google QUIC downgrade prevention mechanism sent over QUIC+TLS. This is // being deprecated in favor of the version_information field below. @@ -229,9 +237,6 @@ // IMMEDIATE_ACK frames. std::optional<uint64_t> min_ack_delay_us_draft10; - // Indicates lack of support for connection migration. - bool disable_active_migration; - // Used to effect a change in server address at the end of the handshake. std::unique_ptr<PreferredAddress> preferred_address; @@ -251,19 +256,28 @@ // the sender accepts. See draft-ietf-quic-datagram. IntegerParameter max_datagram_frame_size; - // Indicates support for the RESET_STREAM_AT frame. - bool reliable_stream_reset; - // Google-specific transport parameter that carries an estimate of the // initial round-trip time in microseconds. IntegerParameter initial_round_trip_time_us; + // Google internal handshake message. + std::optional<std::string> google_handshake_message; + // Data length for TransportParameterId::kDiscard. Negative values means the // parameter is not set. int32_t discard_length = -1; - // Google internal handshake message. - std::optional<std::string> google_handshake_message; + // Represents the sender of the transport parameters. When |perspective| is + // Perspective::IS_CLIENT, this struct is being used in the client_hello + // handshake message; when it is Perspective::IS_SERVER, it is being used in + // the encrypted_extensions handshake message. + Perspective perspective; + + // Indicates lack of support for connection migration. + bool disable_active_migration; + + // Indicates support for the RESET_STREAM_AT frame. + bool reliable_stream_reset; // Debugging Server Name Indication. This is used to send the obfuscated SNI // in the transport parameters to the server for debugging purposes only. @@ -272,18 +286,8 @@ // Google-specific connection options. std::optional<QuicTagVector> google_connection_options; - // Validates whether transport parameters are valid according to - // the specification. If the transport parameters are not valid, this method - // will write a human-readable error message to |error_details|. - bool AreValid(std::string* error_details) const; - // Custom parameters that may be specific to application protocol. ParameterMap custom_parameters; - - // Allows easily logging transport parameters. - std::string ToString() const; - friend QUICHE_EXPORT std::ostream& operator<<( - std::ostream& os, const TransportParameters& params); }; // Serializes a TransportParameters struct into the format for sending it in a