Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Skip to content
Commit b0263af5 authored by Tom Cherry's avatar Tom Cherry
Browse files

logd: remove faulty optimization

TagNameKey contains a pointer to a std::string and a std::string_view,
such it can both own a string or reference a different string.  This
is meant to be a memory optimization.

This, however, is actually a net pessimization.  Due to these three
below cases and typical usage pattern.

Cases:
1) In the case where TagNameKey owns the string, 3 words are wasted,
one for the pointer and two for the std::string_view.

2) In the case where TagNameKey references a short string, the same 3
words are wasted.  This is because std::string has a feature called
"Short String Optimization" that means std::string does not allocate
for strings of sizes <= 10 on 32bit devices and <= 22 on 64bit
devices.

3) In the case where TagNameKey references a longer string than the
"Short String Optimization" limits, then this saves the string's
length in bytes.

Usage pattern:
After boot on 32 bit cuttlefish, there were 679 entries for the first
case, and only 69 in the third case.  The 679 entries have an overhead
of 679 * 3 * sizeof(void*) = 679 * 12 = 8148 bytes.  The 69 strings in
the third case have a total length and therefore savings of 1352
bytes.  This is a net pessimization of 6796 bytes.

I expect this same ratio to be similar throughout the device's uptime.

This situation is worse on 64 bit devices.  If cuttlefish were 64 bit,
then there would have been only 18 items in the third case due to the
larger "Short String Optimization" capacity, and the cost for the
first case would have doubled.

Given the above and the cost of maintaining extra code, this
optimization is removed and a std::string is used as the hash table
key instead.

Test: logging unit tests
Change-Id: I957c519b19edca4f7fc531d96b7144cf68bf4e16
parent 4596b78d
Loading
Loading
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment