Fix O(n) algorithm in INFO command

This commit is contained in:
John Sully 2022-09-12 15:05:09 +00:00
parent 4c1f54da78
commit 5047e64dee
2 changed files with 7 additions and 10 deletions

View File

@ -1142,8 +1142,7 @@ struct redisMemOverhead *getMemoryOverheadData(void) {
mem_total+=mem;
std::unique_lock<fastlock> ul(g_expireLock);
mem = db->setexpire()->bytes_used();
mem = db->setexpire()->estimated_bytes_used();
mh->db[mh->num_dbs].overhead_ht_expires = mem;
mem_total+=mem;

View File

@ -240,14 +240,12 @@ public:
bool empty() const noexcept { return celem == 0; }
size_t size() const noexcept { return celem; }
size_t bytes_used() const
size_t estimated_bytes_used() const
{
size_t cb = sizeof(this) + (m_data.capacity()-m_data.size())*sizeof(T);
for (auto &vec : m_data)
{
if (vec != nullptr)
cb += vec->bytes_used();
}
// This estimate does't include all the overhead of the internal vectors
size_t cb = sizeof(this)
+ (m_data.capacity() * sizeof(m_data[0]))
+ sizeof(T) * size();
return cb;
}