-
Notifications
You must be signed in to change notification settings - Fork 5.5k
Speedups to FakeSymbolTableTest based on microbenchmarks from #6161. #6293
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 13 commits
Commits
Show all changes
15 commits
Select commit
Hold shift + click to select a range
1e11c8b
Speedups to FakeSymbolTableTest based on microbenchmarks from #6161.
jmarantz 91e6d7a
Use SymbolTable::Storage more, and privatize a method that exposes in…
jmarantz d5dfb29
spelling
jmarantz d6f0cce
any -> full
jmarantz a60cd20
Address review comments.
jmarantz fdbc552
Merge branch 'master' into fake-symtab-speedup
jmarantz fac2a11
Improve some comments and method names.
jmarantz d5254bf
Add 'tokenize' and 'tokenizes' to dictionary.
jmarantz 4fc9df1
Merge branch 'master' into fake-symtab-speedup
jmarantz 5737ea8
Merge branch 'master' into fake-symtab-speedup
jmarantz 07aee28
Merge branch 'master' into fake-symtab-speedup
jmarantz e3d6819
Merge branch 'master' into fake-symtab-speedup
jmarantz 2acb4d3
hail-mary to try to get past mysterious 'coverage' build failure.
jmarantz f58722d
Merge branch 'master' into fake-symtab-speedup
jmarantz c94e0d1
Address review comments.
jmarantz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,6 @@ | ||
| #pragma once | ||
|
|
||
| #include <functional> | ||
| #include <memory> | ||
| #include <vector> | ||
|
|
||
|
|
@@ -19,15 +20,7 @@ namespace Stats { | |
| */ | ||
| class StatName; | ||
|
|
||
| /** | ||
| * Intermediate representation for a stat-name. This helps store multiple names | ||
| * in a single packed allocation. First we encode each desired name, then sum | ||
| * their sizes for the single packed allocation. This is used to store | ||
| * MetricImpl's tags and tagExtractedName. Like StatName, we don't want to pay | ||
| * a vptr overhead per object, and the representation is shared between the | ||
| * SymbolTable implementations, so this is just a pre-declare. | ||
| */ | ||
| class SymbolEncoding; | ||
| class StatNameList; | ||
|
|
||
| /** | ||
| * SymbolTable manages a namespace optimized for stat names, exploiting their | ||
|
|
@@ -59,22 +52,6 @@ class SymbolTable { | |
|
|
||
| virtual ~SymbolTable() = default; | ||
|
|
||
| /** | ||
| * Encodes a stat name using the symbol table, returning a SymbolEncoding. The | ||
| * SymbolEncoding is not intended for long-term storage, but is used to help | ||
| * allocate a StatName with the correct amount of storage. | ||
| * | ||
| * When a name is encoded, it bumps reference counts held in the table for | ||
| * each symbol. The caller is responsible for creating a StatName using this | ||
| * SymbolEncoding and ultimately disposing of it by calling | ||
| * SymbolTable::free(). Users are protected from leaking symbols into the pool | ||
| * by ASSERTions in the SymbolTable destructor. | ||
| * | ||
| * @param name The name to encode. | ||
| * @return SymbolEncoding the encoded symbols. | ||
| */ | ||
| virtual SymbolEncoding encode(absl::string_view name) PURE; | ||
|
|
||
| /** | ||
| * @return uint64_t the number of symbols in the symbol table. | ||
| */ | ||
|
|
@@ -116,9 +93,9 @@ class SymbolTable { | |
| * decode/encode into the elaborated form, and does not require locking the | ||
| * SymbolTable. | ||
| * | ||
| * The caveat is that this representation does not bump reference counts on | ||
| * the referenced Symbols in the SymbolTable, so it's only valid as long for | ||
| * the lifetime of the joined StatNames. | ||
| * Note that this method does not bump reference counts on the referenced | ||
| * Symbols in the SymbolTable, so it's only valid as long for the lifetime of | ||
| * the joined StatNames. | ||
| * | ||
| * This is intended for use doing cached name lookups of scoped stats, where | ||
| * the scope prefix and the names to combine it with are already in StatName | ||
|
|
@@ -130,19 +107,54 @@ class SymbolTable { | |
| */ | ||
| virtual StoragePtr join(const std::vector<StatName>& stat_names) const PURE; | ||
|
|
||
| /** | ||
| * Populates a StatNameList from a list of encodings. This is not done at | ||
| * construction time to enable StatNameList to be instantiated directly in | ||
| * a class that doesn't have a live SymbolTable when it is constructed. | ||
| * | ||
| * @param names A pointer to the first name in an array. | ||
| * @param num_names The number of names. | ||
| * @param symbol_table The symbol table in which to encode the names. | ||
| */ | ||
| virtual void populateList(absl::string_view* names, int32_t num_names, StatNameList& list) PURE; | ||
|
|
||
| #ifndef ENVOY_CONFIG_COVERAGE | ||
| virtual void debugPrint() const PURE; | ||
| #endif | ||
|
|
||
| /** | ||
| * Calls the provided function with a string-view representation of the | ||
|
jmarantz marked this conversation as resolved.
|
||
| * elaborated name. This is useful during the interim period when we | ||
| * are using FakeSymbolTableImpl, to avoid an extra allocation. Once | ||
| * we migrate to using SymbolTableImpl, this interface will no longer | ||
| * be helpful and can be removed. The reason it's useful now is that | ||
| * it makes up, in part, for some extra runtime overhead that is spent | ||
| * on the SymbolTable abstraction and API, without getting full benefit | ||
| * from the improved representation. | ||
| * | ||
| * TODO(#6307): Remove this when the transition from FakeSymbolTableImpl to | ||
| * SymbolTableImpl is complete. | ||
| * | ||
| * @param stat_name The stat name. | ||
| * @param fn The function to call with the elaborated stat name as a string_view. | ||
| */ | ||
| virtual void callWithStringView(StatName stat_name, | ||
|
jmarantz marked this conversation as resolved.
|
||
| const std::function<void(absl::string_view)>& fn) const PURE; | ||
|
|
||
| private: | ||
| friend struct HeapStatData; | ||
| friend class StatNameStorage; | ||
| friend class StatNameList; | ||
|
|
||
| // The following methods are private, but are called by friend classes | ||
| // StatNameStorage and StatNameList, which must be friendly with SymbolTable | ||
| // in order to manage the reference-counted symbols they own. | ||
|
|
||
| /** | ||
| * Since SymbolTable does manual reference counting, a client of SymbolTable | ||
| * must manually call free(symbol_vec) when it is freeing the backing store | ||
| * for a StatName. This way, the symbol table will grow and shrink | ||
| * dynamically, instead of being write-only. | ||
| * dynamically, instead of being write-only | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: revert? |
||
| * | ||
| * @param stat_name the stat name. | ||
| */ | ||
|
|
@@ -158,6 +170,17 @@ class SymbolTable { | |
| * @param stat_name the stat name. | ||
| */ | ||
| virtual void incRefCount(const StatName& stat_name) PURE; | ||
|
|
||
| /** | ||
| * Encodes 'name' into the symbol table. Bumps reference counts for referenced | ||
| * symbols. The caller must manage the storage, and is responsible for calling | ||
| * SymbolTable::free() to release the reference counts. | ||
| * | ||
| * @param name The name to encode. | ||
| * @return The encoded name, transferring ownership to the caller. | ||
| * | ||
| */ | ||
| virtual StoragePtr encode(absl::string_view name) PURE; | ||
| }; | ||
|
|
||
| using SharedSymbolTable = std::shared_ptr<SymbolTable>; | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: s/int32_t/uint32_t
Where is this storage coming from? Do we need to use a pointer/length vs. using std:array/std::vector or something like that?