Efl object: implement CoW for the function vtables
authorTom Hacohen <tom@stosb.com>
Mon, 15 Aug 2016 16:11:13 +0000 (17:11 +0100)
committerTom Hacohen <tom@stosb.com>
Tue, 16 Aug 2016 15:29:21 +0000 (16:29 +0100)
commit28c80f91221ae2639f4573046d8621a2a4d18cda
tree59cf734f54a76d2b555904f25e7ff3ffc62575db
parent31f289ff4c4e2b16ce52bb912f4b36ec9ecc92b2
Efl object: implement CoW for the function vtables

This commit implements a sort of CoW for the vtables. The vtables are
usually just linked to and refcounted. When we need to change them we
allocate new ones and copy them over so we can write to them.

I wrote some code to measure the effectiveness of this change. When
running elementary_test (and immediately exiting) I saw that out of the
total number of vtable chains (561) that were needed by the classes in
the EFL, 79 (14.08%) were reused. Considering that I had to add
refcounting (unsigned short, but let's consider it's the size of a word
because of alignment), I would calculate the saving as such (in bytes):

Number of items in a chain (refcounted block): 32

32 bit:
sizeof(chain_node) = 8
Mem wasted on refcounting: 561 * 4 = 2244
Mem saved because of sharing: 79 * (32 * 8) = 20224
Total save: 17980 bytes

64 bit:
sizeof(chain_node) = 16
Mem wasted on refcounting: 561 * 8 = 4488
Mem saved because of sharing: 79 * (32 * 16) = 40448
Total save: 35960 bytes

Wow, we use a lot of memory in Eo classes, I'm sure we can
save even more if we put our hearts into it (change the shareable units
        to be smaller to increase the chance of sharing).
This is internal and doesn't affect API/ABI so we can change this even
further with time.

This also improves efl_object_override(). This should now be quite
memory efficient (don't abuse, but it's not a big hogg as it was), so
feel free to abuse that one and rely on it in API.

@feature
src/lib/eo/eo.c
src/lib/eo/eo_private.h