diff options
author | Frediano Ziglio <fziglio@redhat.com> | 2018-05-13 00:34:26 +0100 |
---|---|---|
committer | Frediano Ziglio <fziglio@redhat.com> | 2018-05-31 07:34:17 +0100 |
commit | 68c0f93889fba893550541b699cb233f2dcbedfc (patch) | |
tree | 15ed7196f15b56a66a0842c6c1d7a7de8307a63a | |
parent | 160232f8f6618763a80bed74c76167beb8361ab6 (diff) |
quic: Remove some too strict asserts in hot paths
Some assert in the code are doing some paranoid test and in code
paths quite hot.
The encoding time is reduced by 30-50% while the decoding time
is reduced by a 20-30%.
Signed-off-by: Frediano Ziglio <fziglio@redhat.com>
Acked-by: Victor Toso <victortoso@redhat.com>
-rw-r--r-- | common/quic.c | 20 | ||||
-rw-r--r-- | common/quic_family_tmpl.c | 4 |
2 files changed, 17 insertions, 7 deletions
diff --git a/common/quic.c b/common/quic.c index a9a82ba..1ec6baa 100644 --- a/common/quic.c +++ b/common/quic.c @@ -400,8 +400,10 @@ static inline void encode(Encoder *encoder, unsigned int word, unsigned int len) { int delta; - spice_assert(len > 0 && len < 32); - spice_assert(!(word & ~bppmask[len])); + if (spice_extra_checks) { + spice_assert(len > 0 && len < 32); + spice_assert(!(word & ~bppmask[len])); + } if ((delta = ((int)encoder->io_available_bits - len)) >= 0) { encoder->io_available_bits = delta; encoder->io_word |= word << encoder->io_available_bits; @@ -413,8 +415,10 @@ static inline void encode(Encoder *encoder, unsigned int word, unsigned int len) encoder->io_available_bits = 32 - delta; encoder->io_word = word << encoder->io_available_bits; - spice_assert(encoder->io_available_bits < 32); - spice_assert((encoder->io_word & bppmask[encoder->io_available_bits]) == 0); + if (spice_extra_checks) { + spice_assert(encoder->io_available_bits < 32); + spice_assert((encoder->io_word & bppmask[encoder->io_available_bits]) == 0); + } } static inline void encode_32(Encoder *encoder, unsigned int word) @@ -437,7 +441,9 @@ static inline void read_io_word(Encoder *encoder) if (encoder->io_now == encoder->io_end) { more_io_words(encoder); } - spice_assert(encoder->io_now < encoder->io_end); + if (spice_extra_checks) { + spice_assert(encoder->io_now < encoder->io_end); + } encoder->io_next_word = GUINT32_FROM_LE(*(encoder->io_now++)); } @@ -445,7 +451,9 @@ static inline void decode_eatbits(Encoder *encoder, int len) { int delta; - spice_assert(len > 0 && len < 32); + if (spice_extra_checks) { + spice_assert(len > 0 && len < 32); + } encoder->io_word <<= len; if ((delta = ((int)encoder->io_available_bits - len)) >= 0) { diff --git a/common/quic_family_tmpl.c b/common/quic_family_tmpl.c index 9450f44..cda15bd 100644 --- a/common/quic_family_tmpl.c +++ b/common/quic_family_tmpl.c @@ -105,7 +105,9 @@ static void FNAME(update_model)(CommonState *state, s_bucket * const bucket, static s_bucket *FNAME(find_bucket)(Channel *channel, const unsigned int val) { - spice_assert(val < (0x1U << BPC)); + if (spice_extra_checks) { + spice_assert(val < (0x1U << BPC)); + } return channel->_buckets_ptrs[val]; } |