-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
tls: maintain a free slot index set in TLS InstanceImpl to allocate in O(1… #7979
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,8 @@ | |
|
||
#include "common/common/logger.h" | ||
|
||
#include "absl/container/flat_hash_set.h" | ||
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: del 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. done. |
||
|
||
namespace Envoy { | ||
namespace ThreadLocal { | ||
|
||
|
@@ -57,6 +59,9 @@ class InstanceImpl : Logger::Loggable<Logger::Id::main>, public Instance { | |
|
||
static thread_local ThreadLocalData thread_local_data_; | ||
std::vector<SlotImpl*> slots_; | ||
// A set of index of freed slots. | ||
absl::flat_hash_set<uint32_t> free_slot_indexes_; | ||
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. I think you can just use std::list here? 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. if we don't care about the assertion around when we return the slot, we can use a list here. Please let me know if you prefer to change to list. |
||
|
||
std::list<std::reference_wrapper<Event::Dispatcher>> registered_threads_; | ||
std::thread::id main_thread_id_; | ||
Event::Dispatcher* main_thread_dispatcher_{}; | ||
|
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.
With std::list you can do a similar assert using find
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.
find is again O(N), and in this case it will go over the full list (as there won't be such a idx if we do things right here)
But if we don't care about the assertion, we can use std::list which is also O(1) allocation/return.
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.
Yeah I would just switch to list. I don't think the perf of the assertion matters. Thank you!
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.
change to std::list.
For some reason I thought ASSERT won't be compiled out. :/