Merge pull request #16663 from hcaseyal/delete_unecessary_callout_checks

Remove unnecessary callout_is_default checks
pull/13653/merge
hcaseyal 6 years ago committed by GitHub
commit 0dd651dcea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 4
      src/core/lib/transport/metadata_batch.cc
  2. 27
      src/core/lib/transport/static_metadata.cc
  3. 2
      src/core/lib/transport/static_metadata.h
  4. 71
      tools/codegen/core/gen_static_metadata.py

@ -105,7 +105,7 @@ static grpc_error* maybe_link_callout(grpc_metadata_batch* batch,
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
if (batch->idx.array[idx] == nullptr) { if (batch->idx.array[idx] == nullptr) {
if (grpc_static_callout_is_default[idx]) ++batch->list.default_count; ++batch->list.default_count;
batch->idx.array[idx] = storage; batch->idx.array[idx] = storage;
return GRPC_ERROR_NONE; return GRPC_ERROR_NONE;
} }
@ -121,7 +121,7 @@ static void maybe_unlink_callout(grpc_metadata_batch* batch,
if (idx == GRPC_BATCH_CALLOUTS_COUNT) { if (idx == GRPC_BATCH_CALLOUTS_COUNT) {
return; return;
} }
if (grpc_static_callout_is_default[idx]) --batch->list.default_count; --batch->list.default_count;
GPR_ASSERT(batch->idx.array[idx] != nullptr); GPR_ASSERT(batch->idx.array[idx] != nullptr);
batch->idx.array[idx] = nullptr; batch->idx.array[idx] = nullptr;
} }

@ -568,33 +568,6 @@ grpc_mdelem_data grpc_static_mdelem_table[GRPC_STATIC_MDELEM_COUNT] = {
{{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}}, {{&grpc_static_metadata_refcounts[16], {{g_bytes + 186, 15}}},
{&grpc_static_metadata_refcounts[102], {{g_bytes + 1101, 13}}}}, {&grpc_static_metadata_refcounts[102], {{g_bytes + 1101, 13}}}},
}; };
bool grpc_static_callout_is_default[GRPC_BATCH_CALLOUTS_COUNT] = {
true, // :path
true, // :method
true, // :status
true, // :authority
true, // :scheme
true, // te
true, // grpc-message
true, // grpc-status
true, // grpc-payload-bin
true, // grpc-encoding
true, // grpc-accept-encoding
true, // grpc-server-stats-bin
true, // grpc-tags-bin
true, // grpc-trace-bin
true, // content-type
true, // content-encoding
true, // accept-encoding
true, // grpc-internal-encoding-request
true, // grpc-internal-stream-encoding-request
true, // user-agent
true, // host
true, // lb-token
true, // grpc-previous-rpc-attempts
true, // grpc-retry-pushback-ms
};
const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 76, 77, 78, const uint8_t grpc_static_accept_encoding_metadata[8] = {0, 76, 77, 78,
79, 80, 81, 82}; 79, 80, 81, 82};

@ -587,8 +587,6 @@ typedef union {
GRPC_BATCH_CALLOUTS_COUNT) \ GRPC_BATCH_CALLOUTS_COUNT) \
: GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)
extern bool grpc_static_callout_is_default[GRPC_BATCH_CALLOUTS_COUNT];
extern const uint8_t grpc_static_accept_encoding_metadata[8]; extern const uint8_t grpc_static_accept_encoding_metadata[8];
#define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \ #define GRPC_MDELEM_ACCEPT_ENCODING_FOR_ALGORITHMS(algs) \
(GRPC_MAKE_MDELEM( \ (GRPC_MAKE_MDELEM( \

@ -146,35 +146,34 @@ CONFIG = [
('www-authenticate', '', 61), ('www-authenticate', '', 61),
] ]
# Entries marked with is_default=True are ignored when counting # All entries here are ignored when counting non-default initial metadata that
# non-default initial metadata that prevents the chttp2 server from # prevents the chttp2 server from sending a Trailers-Only response.
# sending a Trailers-Only response.
METADATA_BATCH_CALLOUTS = [ METADATA_BATCH_CALLOUTS = [
# (name, is_default) # (name)
(':path', True), (':path'),
(':method', True), (':method'),
(':status', True), (':status'),
(':authority', True), (':authority'),
(':scheme', True), (':scheme'),
('te', True), ('te'),
('grpc-message', True), ('grpc-message'),
('grpc-status', True), ('grpc-status'),
('grpc-payload-bin', True), ('grpc-payload-bin'),
('grpc-encoding', True), ('grpc-encoding'),
('grpc-accept-encoding', True), ('grpc-accept-encoding'),
('grpc-server-stats-bin', True), ('grpc-server-stats-bin'),
('grpc-tags-bin', True), ('grpc-tags-bin'),
('grpc-trace-bin', True), ('grpc-trace-bin'),
('content-type', True), ('content-type'),
('content-encoding', True), ('content-encoding'),
('accept-encoding', True), ('accept-encoding'),
('grpc-internal-encoding-request', True), ('grpc-internal-encoding-request'),
('grpc-internal-stream-encoding-request', True), ('grpc-internal-stream-encoding-request'),
('user-agent', True), ('user-agent'),
('host', True), ('host'),
('lb-token', True), ('lb-token'),
('grpc-previous-rpc-attempts', True), ('grpc-previous-rpc-attempts'),
('grpc-retry-pushback-ms', True), ('grpc-retry-pushback-ms'),
] ]
COMPRESSION_ALGORITHMS = [ COMPRESSION_ALGORITHMS = [
@ -256,7 +255,7 @@ all_elems = list()
static_userdata = {} static_userdata = {}
# put metadata batch callouts first, to make the check of if a static metadata # put metadata batch callouts first, to make the check of if a static metadata
# string is a callout trivial # string is a callout trivial
for elem, _ in METADATA_BATCH_CALLOUTS: for elem in METADATA_BATCH_CALLOUTS:
if elem not in all_strs: if elem not in all_strs:
all_strs.append(elem) all_strs.append(elem)
for elem in CONFIG: for elem in CONFIG:
@ -432,7 +431,7 @@ def slice_def(i):
# validate configuration # validate configuration
for elem, _ in METADATA_BATCH_CALLOUTS: for elem in METADATA_BATCH_CALLOUTS:
assert elem in all_strs assert elem in all_strs
print >> H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs) print >> H, '#define GRPC_STATIC_MDSTR_COUNT %d' % len(all_strs)
@ -614,7 +613,7 @@ for elem in all_elems:
print >> C, '};' print >> C, '};'
print >> H, 'typedef enum {' print >> H, 'typedef enum {'
for elem, _ in METADATA_BATCH_CALLOUTS: for elem in METADATA_BATCH_CALLOUTS:
print >> H, ' %s,' % mangle(elem, 'batch').upper() print >> H, ' %s,' % mangle(elem, 'batch').upper()
print >> H, ' GRPC_BATCH_CALLOUTS_COUNT' print >> H, ' GRPC_BATCH_CALLOUTS_COUNT'
print >> H, '} grpc_metadata_batch_callouts_index;' print >> H, '} grpc_metadata_batch_callouts_index;'
@ -622,7 +621,7 @@ print >> H
print >> H, 'typedef union {' print >> H, 'typedef union {'
print >> H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];' print >> H, ' struct grpc_linked_mdelem *array[GRPC_BATCH_CALLOUTS_COUNT];'
print >> H, ' struct {' print >> H, ' struct {'
for elem, _ in METADATA_BATCH_CALLOUTS: for elem in METADATA_BATCH_CALLOUTS:
print >> H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower() print >> H, ' struct grpc_linked_mdelem *%s;' % mangle(elem, '').lower()
print >> H, ' } named;' print >> H, ' } named;'
print >> H, '} grpc_metadata_batch_callouts;' print >> H, '} grpc_metadata_batch_callouts;'
@ -630,14 +629,6 @@ print >> H
print >> H, '#define GRPC_BATCH_INDEX_OF(slice) \\' print >> H, '#define GRPC_BATCH_INDEX_OF(slice) \\'
print >> H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)' print >> H, ' (GRPC_IS_STATIC_METADATA_STRING((slice)) ? (grpc_metadata_batch_callouts_index)GPR_CLAMP(GRPC_STATIC_METADATA_INDEX((slice)), 0, GRPC_BATCH_CALLOUTS_COUNT) : GRPC_BATCH_CALLOUTS_COUNT)'
print >> H print >> H
print >> H, ('extern bool grpc_static_callout_is_default['
'GRPC_BATCH_CALLOUTS_COUNT];')
print >> H
print >> C, 'bool grpc_static_callout_is_default[GRPC_BATCH_CALLOUTS_COUNT] = {'
for elem, is_default in METADATA_BATCH_CALLOUTS:
print >> C, ' %s, // %s' % (str(is_default).lower(), elem)
print >> C, '};'
print >> C
print >> H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % ( print >> H, 'extern const uint8_t grpc_static_accept_encoding_metadata[%d];' % (
1 << len(COMPRESSION_ALGORITHMS)) 1 << len(COMPRESSION_ALGORITHMS))

Loading…
Cancel
Save