From ae6f620d6c3cb65f0b534b99a3737ea56005bfa9 Mon Sep 17 00:00:00 2001 From: Hope Casey-Allen Date: Thu, 20 Sep 2018 14:55:05 -0700 Subject: [PATCH] Add comment to explain obscure performance choice --- src/core/ext/transport/chttp2/transport/parsing.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/core/ext/transport/chttp2/transport/parsing.cc b/src/core/ext/transport/chttp2/transport/parsing.cc index 8ffd4de17c6..8e9aa613a6e 100644 --- a/src/core/ext/transport/chttp2/transport/parsing.cc +++ b/src/core/ext/transport/chttp2/transport/parsing.cc @@ -410,6 +410,12 @@ static void on_initial_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC) { + // We don't use grpc_mdelem_eq here to avoid executing additional + // instructions. The reasoning is if the payload is not equal, we already + // know that the metadata elements are not equal because the md is + // confirmed to be static. If we had used grpc_mdelem_eq here, then if the + // payloads are not equal, grpc_mdelem_eq executes more instructions to + // determine if they're equal or not. if (md.payload == GRPC_MDELEM_GRPC_STATUS_1.payload || md.payload == GRPC_MDELEM_GRPC_STATUS_2.payload) { s->seen_error = true; @@ -500,6 +506,12 @@ static void on_trailing_header(void* tp, grpc_mdelem md) { } if (GRPC_MDELEM_STORAGE(md) == GRPC_MDELEM_STORAGE_STATIC) { + // We don't use grpc_mdelem_eq here to avoid executing additional + // instructions. The reasoning is if the payload is not equal, we already + // know that the metadata elements are not equal because the md is + // confirmed to be static. If we had used grpc_mdelem_eq here, then if the + // payloads are not equal, grpc_mdelem_eq executes more instructions to + // determine if they're equal or not. if (md.payload == GRPC_MDELEM_GRPC_STATUS_1.payload || md.payload == GRPC_MDELEM_GRPC_STATUS_2.payload) { s->seen_error = true;