Skip to content

tls: performance of allocating slot could be improved, it's O(N) for now. #7975

@stevenzzzz

Description

@stevenzzzz

Issue Template

Title: Allocating a slot currently including a linear searching for empty slot in the slots vector, in the case of frequent allocating and deallocating, this could be a performance issue.

Description:

in InstanceImpl::allocateSlot, a linear search is done before expanding the slots_'s size.

https://github.com/envoyproxy/envoy/blob/master/source/common/thread_local/thread_local_impl.cc

for (uint64_t i = 0; i < slots_.size(); i++) {
if (slots_[i] == nullptr) {
std::unique_ptr slot(new SlotImpl(*this, i));
slots_[i] = slot.get();
return slot;
}
}

We can maintain a free list to return existing free slot in O(1).

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions