Skip to content

Commit 19a6722

Browse files
adicatanafacebook-github-bot
authored andcommitted
Annotate some static initializers with CLANG_LAZY_INIT_TEST
Summary: **Context**: Eagerly run static initializers are bad for the performance of our apps, especially when this code is loaded early on. We are trying to make them lazy, either by switching simple strings to constexpr/std::string_view or by using a new compiler optimization that transforms the code according to the construct on first use idiom. **This diff**: As in the title, these initializers are called for M4A's libcoldstart, let's test delaying them as part of an APK A/B. Since most of these are strings, we'll want to change the annotation to constexpr/std::string_view after running the tests to capture perf/reliability implications. Reviewed By: smeenai Differential Revision: D74729953 fbshipit-source-id: 3d746ade78e59374aeacc6b1461845def55588a1
1 parent b8d91bc commit 19a6722

File tree

8 files changed

+103
-60
lines changed

8 files changed

+103
-60
lines changed

third-party/proxygen/src/proxygen/lib/http/HTTPHeaders.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323

2424
namespace proxygen {
2525

26-
extern const std::string empty_string;
26+
#ifndef CLANG_LAZY_INIT_TEST
27+
#define CLANG_LAZY_INIT_TEST
28+
#endif
29+
30+
CLANG_LAZY_INIT_TEST extern const std::string empty_string;
2731

2832
/**
2933
* Return true if the character is linear whitespace, as defined by the LWS
@@ -89,11 +93,15 @@ class HTTPHeaders {
8993
using headers_initializer_list =
9094
std::initializer_list<std::pair<HTTPHeaderName, folly::StringPiece>>;
9195

96+
#ifndef CLANG_LAZY_INIT_TEST
97+
#define CLANG_LAZY_INIT_TEST
98+
#endif
99+
92100
/*
93101
* separator used to concatenate multiple values of the same header
94102
* check out sections 4.2 and 14.45 from rfc2616
95103
*/
96-
static const std::string COMBINE_SEPARATOR;
104+
CLANG_LAZY_INIT_TEST static const std::string COMBINE_SEPARATOR;
97105

98106
FB_EXPORT HTTPHeaders();
99107
FB_EXPORT ~HTTPHeaders();

third-party/proxygen/src/proxygen/lib/http/HeaderConstants.h

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -11,18 +11,23 @@
1111
#include <string>
1212

1313
namespace proxygen::headers {
14-
extern const std::string kAuthority;
15-
extern const std::string kMethod;
16-
extern const std::string kPath;
17-
extern const std::string kScheme;
18-
extern const std::string kStatus;
19-
extern const std::string kProtocol;
20-
21-
extern const std::string kHttp;
22-
extern const std::string kHttps;
23-
extern const std::string kMasque;
24-
25-
extern const std::string kWebsocketString;
26-
extern const std::string kStatus200;
14+
15+
#ifndef CLANG_LAZY_INIT_TEST
16+
#define CLANG_LAZY_INIT_TEST
17+
#endif
18+
19+
CLANG_LAZY_INIT_TEST extern const std::string kAuthority;
20+
CLANG_LAZY_INIT_TEST extern const std::string kMethod;
21+
CLANG_LAZY_INIT_TEST extern const std::string kPath;
22+
CLANG_LAZY_INIT_TEST extern const std::string kScheme;
23+
CLANG_LAZY_INIT_TEST extern const std::string kStatus;
24+
CLANG_LAZY_INIT_TEST extern const std::string kProtocol;
25+
26+
CLANG_LAZY_INIT_TEST extern const std::string kHttp;
27+
CLANG_LAZY_INIT_TEST extern const std::string kHttps;
28+
CLANG_LAZY_INIT_TEST extern const std::string kMasque;
29+
30+
CLANG_LAZY_INIT_TEST extern const std::string kWebsocketString;
31+
CLANG_LAZY_INIT_TEST extern const std::string kStatus200;
2732

2833
} // namespace proxygen::headers

third-party/proxygen/src/proxygen/lib/http/codec/CodecProtocol.cpp

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,18 @@
1919
namespace proxygen {
2020

2121
namespace {
22-
static const std::string http_1_1 = "http/1.1";
23-
static const std::string http_2 = "http/2";
24-
static const std::string hq = "hq";
25-
static const std::string h3 = "h3";
26-
static const std::string http_binary = "bhttp";
27-
static const std::string tunnel_lite = "lite";
28-
static const std::string empty;
22+
23+
#ifndef CLANG_LAZY_INIT_TEST
24+
#define CLANG_LAZY_INIT_TEST
25+
#endif
26+
27+
CLANG_LAZY_INIT_TEST static const std::string http_1_1 = "http/1.1";
28+
CLANG_LAZY_INIT_TEST static const std::string http_2 = "http/2";
29+
CLANG_LAZY_INIT_TEST static const std::string hq = "hq";
30+
CLANG_LAZY_INIT_TEST static const std::string h3 = "h3";
31+
CLANG_LAZY_INIT_TEST static const std::string http_binary = "bhttp";
32+
CLANG_LAZY_INIT_TEST static const std::string tunnel_lite = "lite";
33+
CLANG_LAZY_INIT_TEST static const std::string empty;
2934
} // namespace
3035

3136
extern CodecProtocol getCodecProtocolFromStr(folly::StringPiece protocolStr) {

third-party/proxygen/src/proxygen/lib/http/codec/HTTP1xCodec.cpp

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,11 @@ using std::unique_ptr;
2525

2626
namespace {
2727

28-
static const std::string kChunked = "chunked";
28+
#ifndef CLANG_LAZY_INIT_TEST
29+
#define CLANG_LAZY_INIT_TEST
30+
#endif
31+
32+
CLANG_LAZY_INIT_TEST static const std::string kChunked = "chunked";
2933
const char CRLF[] = "\r\n";
3034

3135
/**

third-party/proxygen/src/proxygen/lib/http/codec/HTTP2Constants.h

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,17 @@ extern const uint32_t kMaxHeaderTableSize;
4141
extern const uint32_t kMaxAuthenticatorBufSize;
4242

4343
extern const uint32_t kMaxHeaderTableSize;
44-
extern const std::string kConnectionPreface;
4544

46-
extern const std::string kProtocolString;
47-
extern const std::string kProtocolDraftString;
48-
extern const std::string kProtocolExperimentalString;
49-
extern const std::string kProtocolCleartextString;
50-
extern const std::string kProtocolSettingsHeader;
45+
#ifndef CLANG_LAZY_INIT_TEST
46+
#define CLANG_LAZY_INIT_TEST
47+
#endif
48+
49+
CLANG_LAZY_INIT_TEST extern const std::string kConnectionPreface;
50+
51+
CLANG_LAZY_INIT_TEST extern const std::string kProtocolString;
52+
CLANG_LAZY_INIT_TEST extern const std::string kProtocolDraftString;
53+
CLANG_LAZY_INIT_TEST extern const std::string kProtocolExperimentalString;
54+
CLANG_LAZY_INIT_TEST extern const std::string kProtocolCleartextString;
55+
CLANG_LAZY_INIT_TEST extern const std::string kProtocolSettingsHeader;
5156

5257
} // namespace proxygen::http2

third-party/proxygen/src/proxygen/lib/http/session/HQSession.cpp

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,12 @@
3636

3737
namespace {
3838
static const uint16_t kMaxReadsPerLoop = 16;
39-
static const std::string kQUICProtocolName("QUIC");
39+
40+
#ifndef CLANG_LAZY_INIT_TEST
41+
#define CLANG_LAZY_INIT_TEST
42+
#endif
43+
44+
CLANG_LAZY_INIT_TEST static const std::string kQUICProtocolName("QUIC");
4045
constexpr uint64_t kMaxQuarterStreamId = (1ull << 60) - 1;
4146

4247
using namespace proxygen::HTTP3;
@@ -145,15 +150,15 @@ using namespace proxygen::hq;
145150

146151
namespace proxygen {
147152

148-
const std::string kH3FBCurrentDraft("h3-fb-05");
149-
const std::string kH3AliasV1("h3-alias-01");
150-
const std::string kH3AliasV2("h3-alias-02");
151-
const std::string kH3("h3");
152-
const std::string kHQ("hq-interop");
153+
CLANG_LAZY_INIT_TEST const std::string kH3FBCurrentDraft("h3-fb-05");
154+
CLANG_LAZY_INIT_TEST const std::string kH3AliasV1("h3-alias-01");
155+
CLANG_LAZY_INIT_TEST const std::string kH3AliasV2("h3-alias-02");
156+
CLANG_LAZY_INIT_TEST const std::string kH3("h3");
157+
CLANG_LAZY_INIT_TEST const std::string kHQ("hq-interop");
153158

154159
// TODO: remove these constants, the library no longer negotiates them
155-
const std::string kH3CurrentDraft("h3-29");
156-
const std::string kHQCurrentDraft("hq-29");
160+
CLANG_LAZY_INIT_TEST const std::string kH3CurrentDraft("h3-29");
161+
CLANG_LAZY_INIT_TEST const std::string kHQCurrentDraft("hq-29");
157162

158163
const http2::PriorityUpdate hqDefaultPriority{kSessionStreamId, false, 15};
159164

third-party/proxygen/src/proxygen/lib/http/session/HQSession.h

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -53,14 +53,18 @@ enum class HQVersion : uint8_t {
5353
HQ, // The real McCoy
5454
};
5555

56-
extern const std::string kH3;
57-
extern const std::string kH3AliasV1;
58-
extern const std::string kH3AliasV2;
59-
extern const std::string kHQ;
60-
extern const std::string kH3FBCurrentDraft;
56+
#ifndef CLANG_LAZY_INIT_TEST
57+
#define CLANG_LAZY_INIT_TEST
58+
#endif
59+
60+
CLANG_LAZY_INIT_TEST extern const std::string kH3;
61+
CLANG_LAZY_INIT_TEST extern const std::string kH3AliasV1;
62+
CLANG_LAZY_INIT_TEST extern const std::string kH3AliasV2;
63+
CLANG_LAZY_INIT_TEST extern const std::string kHQ;
64+
CLANG_LAZY_INIT_TEST extern const std::string kH3FBCurrentDraft;
6165
// TODO: Remove these constants, the session no longer negotiates these
62-
extern const std::string kH3CurrentDraft;
63-
extern const std::string kHQCurrentDraft;
66+
CLANG_LAZY_INIT_TEST extern const std::string kH3CurrentDraft;
67+
CLANG_LAZY_INIT_TEST extern const std::string kHQCurrentDraft;
6468

6569
// Default Priority Node
6670
extern const proxygen::http2::PriorityUpdate hqDefaultPriority;

third-party/proxygen/src/proxygen/lib/http/structuredheaders/StructuredHeadersConstants.h

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -90,21 +90,28 @@ enum class EncodeError : uint8_t {
9090
ENCODING_NULL_ITEM = 5
9191
};
9292

93-
static const std::map<DecodeError, std::string> decodeErrorDescription{
94-
{DecodeError::OK, "No error"},
95-
{DecodeError::VALUE_TOO_LONG, "Numeric value is too long"},
96-
{DecodeError::INVALID_CHARACTER, "Invalid character"},
97-
{DecodeError::UNDECODEABLE_BINARY_CONTENT, "Undecodable binary content"},
98-
{DecodeError::UNEXPECTED_END_OF_BUFFER, "Unexpected end of buffer"},
99-
{DecodeError::UNPARSEABLE_NUMERIC_TYPE, "Unparseable numeric type"},
100-
{DecodeError::DUPLICATE_KEY, "Duplicate key found"}};
101-
102-
static const std::map<EncodeError, std::string> encodeErrorDescription{
103-
{EncodeError::OK, "No error"},
104-
{EncodeError::EMPTY_DATA_STRUCTURE, "Empty data structure"},
105-
{EncodeError::BAD_IDENTIFIER, "Bad identifier"},
106-
{EncodeError::BAD_STRING, "Bad string"},
107-
{EncodeError::ITEM_TYPE_MISMATCH, "Item type mismatch"},
108-
{EncodeError::ENCODING_NULL_ITEM, "Tried to encode null item"}};
93+
#ifndef CLANG_LAZY_INIT_TEST
94+
#define CLANG_LAZY_INIT_TEST
95+
#endif
96+
97+
CLANG_LAZY_INIT_TEST static const std::map<DecodeError, std::string>
98+
decodeErrorDescription{
99+
{DecodeError::OK, "No error"},
100+
{DecodeError::VALUE_TOO_LONG, "Numeric value is too long"},
101+
{DecodeError::INVALID_CHARACTER, "Invalid character"},
102+
{DecodeError::UNDECODEABLE_BINARY_CONTENT,
103+
"Undecodable binary content"},
104+
{DecodeError::UNEXPECTED_END_OF_BUFFER, "Unexpected end of buffer"},
105+
{DecodeError::UNPARSEABLE_NUMERIC_TYPE, "Unparseable numeric type"},
106+
{DecodeError::DUPLICATE_KEY, "Duplicate key found"}};
107+
108+
CLANG_LAZY_INIT_TEST static const std::map<EncodeError, std::string>
109+
encodeErrorDescription{
110+
{EncodeError::OK, "No error"},
111+
{EncodeError::EMPTY_DATA_STRUCTURE, "Empty data structure"},
112+
{EncodeError::BAD_IDENTIFIER, "Bad identifier"},
113+
{EncodeError::BAD_STRING, "Bad string"},
114+
{EncodeError::ITEM_TYPE_MISMATCH, "Item type mismatch"},
115+
{EncodeError::ENCODING_NULL_ITEM, "Tried to encode null item"}};
109116

110117
} // namespace proxygen::StructuredHeaders

0 commit comments

Comments
 (0)