[hpack] Use NoDestruct type to simplify HPackTable (#30496)

* [hpack] Use NoDestruct type to simplify HPackTable

* experiment
pull/30774/head
Craig Tiller 2 years ago committed by GitHub
parent b8605a424e
commit 71a3ba1c5c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 1
      BUILD
  2. 11
      src/core/ext/transport/chttp2/transport/hpack_parser_table.cc
  3. 10
      src/core/ext/transport/chttp2/transport/hpack_parser_table.h

@ -6567,6 +6567,7 @@ grpc_cc_library(
"iomgr_fwd",
"iomgr_timer",
"memory_quota",
"no_destruct",
"poll",
"ref_counted",
"ref_counted_ptr",

@ -78,10 +78,6 @@ void HPackTable::MementoRingBuffer::Rebuild(uint32_t max_entries) {
entries_.swap(entries);
}
HPackTable::HPackTable() : static_metadata_(GetStaticMementos()) {}
HPackTable::~HPackTable() = default;
/* Evict one element from the table */
void HPackTable::EvictOne() {
auto first_entry = entries_.PopOne();
@ -229,7 +225,7 @@ const StaticTableEntry kStaticTable[hpack_constants::kLastStaticEntry] = {
{"www-authenticate", ""},
};
GPR_ATTRIBUTE_NOINLINE HPackTable::Memento MakeMemento(size_t i) {
HPackTable::Memento MakeMemento(size_t i) {
auto sm = kStaticTable[i];
return grpc_metadata_batch::Parse(
sm.key, Slice::FromStaticString(sm.value),
@ -241,11 +237,6 @@ GPR_ATTRIBUTE_NOINLINE HPackTable::Memento MakeMemento(size_t i) {
} // namespace
auto HPackTable::GetStaticMementos() -> const StaticMementos& {
static const StaticMementos* const static_mementos = new StaticMementos();
return *static_mementos;
}
HPackTable::StaticMementos::StaticMementos() {
for (uint32_t i = 0; i < hpack_constants::kLastStaticEntry; i++) {
memento[i] = MakeMemento(i);

@ -26,6 +26,7 @@
#include <vector>
#include "src/core/ext/transport/chttp2/transport/hpack_constants.h"
#include "src/core/lib/gprpp/no_destruct.h"
#include "src/core/lib/iomgr/error.h"
#include "src/core/lib/transport/metadata_batch.h"
#include "src/core/lib/transport/parsed_metadata.h"
@ -35,8 +36,8 @@ namespace grpc_core {
// HPACK header table
class HPackTable {
public:
HPackTable();
~HPackTable();
HPackTable() = default;
~HPackTable() = default;
HPackTable(const HPackTable&) = delete;
HPackTable& operator=(const HPackTable&) = delete;
@ -55,7 +56,7 @@ class HPackTable {
// reading the core static metadata table here; at that point we'd need our
// own singleton static metadata in the correct order.
if (index <= hpack_constants::kLastStaticEntry) {
return &static_metadata_.memento[index - 1];
return &NoDestructSingleton<StaticMementos>::Get()->memento[index - 1];
} else {
return LookupDynamic(index);
}
@ -72,7 +73,6 @@ class HPackTable {
StaticMementos();
Memento memento[hpack_constants::kLastStaticEntry];
};
static const StaticMementos& GetStaticMementos() GPR_ATTRIBUTE_NOINLINE;
class MementoRingBuffer {
public:
@ -123,8 +123,6 @@ class HPackTable {
uint32_t current_table_bytes_ = hpack_constants::kInitialTableSize;
// HPack table entries
MementoRingBuffer entries_;
// Mementos for static data
const StaticMementos& static_metadata_;
};
} // namespace grpc_core

Loading…
Cancel
Save