forked from enlightenment/efl
edje - reduce anothr 400k or so of memory usage (esp hello world)
so edje was allocating 32 pointers per collection. this is per collection inside an edje file even if we just use one collection from that edje file. it consumes 32 pointers. on 64bit thats 256 bytes... just for pointers to mempools so we can "optimize" freeing and allocation of parts. this was simply rediculous. i moved it to a sub-struct allocated on demand (so now only for collections we actually use) and this nuked 400k of "base memory usage youcant get rid of). note that our current default theme has something like 1100 or so images, 1500 or so collections in it. as theme gorws, memory footprint goes up if we dont allocation only on demand (when needed/used) and we aren't careful about the size of our data structs and their content. @optimize
This commit is contained in:
parent
3b02375290
commit
6139c7a3c6
|
@ -9,18 +9,22 @@ static int _edje_collection_cache_size = 16;
|
|||
|
||||
EAPI void
|
||||
edje_cache_emp_alloc(Edje_Part_Collection_Directory_Entry *ce)
|
||||
{ /* Init Eina Mempools this is also used in edje_pick.c */
|
||||
char *buffer;
|
||||
#define INIT_EMP(Tp, Sz, Ce) \
|
||||
buffer = alloca(strlen(ce->entry) + strlen(#Tp) + 2); \
|
||||
sprintf(buffer, "%s/%s", ce->entry, #Tp); \
|
||||
Ce->mp.Tp = eina_mempool_add("one_big", buffer, NULL, sizeof (Sz), Ce->count.Tp); \
|
||||
_emp_##Tp = Ce->mp.Tp;
|
||||
{
|
||||
/* Init Eina Mempools this is also used in edje_pick.c */
|
||||
char *buffer;
|
||||
ce->mp = calloc(1, sizeof(Edje_Part_Collection_Directory_Entry_Mp));
|
||||
if (!ce->mp) return;
|
||||
|
||||
#define INIT_EMP_BOTH(Tp, Sz, Ce) \
|
||||
INIT_EMP(Tp, Sz, Ce) \
|
||||
Ce->mp_rtl.Tp = eina_mempool_add("one_big", buffer, NULL, \
|
||||
sizeof (Sz), Ce->count.Tp);
|
||||
#define INIT_EMP(Tp, Sz, Ce) \
|
||||
buffer = alloca(strlen(ce->entry) + strlen(#Tp) + 2); \
|
||||
sprintf(buffer, "%s/%s", ce->entry, #Tp); \
|
||||
Ce->mp->mp.Tp = eina_mempool_add("one_big", buffer, NULL, sizeof (Sz), Ce->count.Tp); \
|
||||
_emp_##Tp = Ce->mp->mp.Tp;
|
||||
|
||||
#define INIT_EMP_BOTH(Tp, Sz, Ce) \
|
||||
INIT_EMP(Tp, Sz, Ce) \
|
||||
Ce->mp->mp_rtl.Tp = eina_mempool_add("one_big", buffer, NULL, \
|
||||
sizeof(Sz), Ce->count.Tp);
|
||||
|
||||
INIT_EMP_BOTH(RECTANGLE, Edje_Part_Description_Common, ce);
|
||||
INIT_EMP_BOTH(TEXT, Edje_Part_Description_Text, ce);
|
||||
|
@ -45,42 +49,44 @@ EAPI void
|
|||
edje_cache_emp_free(Edje_Part_Collection_Directory_Entry *ce)
|
||||
{ /* Free Eina Mempools this is also used in edje_pick.c */
|
||||
/* Destroy all part and description. */
|
||||
eina_mempool_del(ce->mp.RECTANGLE);
|
||||
eina_mempool_del(ce->mp.TEXT);
|
||||
eina_mempool_del(ce->mp.IMAGE);
|
||||
eina_mempool_del(ce->mp.PROXY);
|
||||
eina_mempool_del(ce->mp.SWALLOW);
|
||||
eina_mempool_del(ce->mp.TEXTBLOCK);
|
||||
eina_mempool_del(ce->mp.GROUP);
|
||||
eina_mempool_del(ce->mp.BOX);
|
||||
eina_mempool_del(ce->mp.TABLE);
|
||||
eina_mempool_del(ce->mp.EXTERNAL);
|
||||
eina_mempool_del(ce->mp.SPACER);
|
||||
eina_mempool_del(ce->mp.SNAPSHOT);
|
||||
eina_mempool_del(ce->mp.MESH_NODE);
|
||||
eina_mempool_del(ce->mp.LIGHT);
|
||||
eina_mempool_del(ce->mp.CAMERA);
|
||||
eina_mempool_del(ce->mp.VECTOR);
|
||||
eina_mempool_del(ce->mp.part);
|
||||
memset(&ce->mp, 0, sizeof (ce->mp));
|
||||
ce->ref = NULL;
|
||||
|
||||
eina_mempool_del(ce->mp_rtl.RECTANGLE);
|
||||
eina_mempool_del(ce->mp_rtl.TEXT);
|
||||
eina_mempool_del(ce->mp_rtl.IMAGE);
|
||||
eina_mempool_del(ce->mp_rtl.PROXY);
|
||||
eina_mempool_del(ce->mp_rtl.SWALLOW);
|
||||
eina_mempool_del(ce->mp_rtl.TEXTBLOCK);
|
||||
eina_mempool_del(ce->mp_rtl.GROUP);
|
||||
eina_mempool_del(ce->mp_rtl.BOX);
|
||||
eina_mempool_del(ce->mp_rtl.TABLE);
|
||||
eina_mempool_del(ce->mp_rtl.EXTERNAL);
|
||||
eina_mempool_del(ce->mp_rtl.SPACER);
|
||||
eina_mempool_del(ce->mp_rtl.SNAPSHOT);
|
||||
eina_mempool_del(ce->mp_rtl.MESH_NODE);
|
||||
eina_mempool_del(ce->mp_rtl.LIGHT);
|
||||
eina_mempool_del(ce->mp_rtl.CAMERA);
|
||||
memset(&ce->mp_rtl, 0, sizeof (ce->mp_rtl));
|
||||
ce->ref = NULL;
|
||||
if (!ce->mp) return;
|
||||
eina_mempool_del(ce->mp->mp.RECTANGLE);
|
||||
eina_mempool_del(ce->mp->mp.TEXT);
|
||||
eina_mempool_del(ce->mp->mp.IMAGE);
|
||||
eina_mempool_del(ce->mp->mp.PROXY);
|
||||
eina_mempool_del(ce->mp->mp.SWALLOW);
|
||||
eina_mempool_del(ce->mp->mp.TEXTBLOCK);
|
||||
eina_mempool_del(ce->mp->mp.GROUP);
|
||||
eina_mempool_del(ce->mp->mp.BOX);
|
||||
eina_mempool_del(ce->mp->mp.TABLE);
|
||||
eina_mempool_del(ce->mp->mp.EXTERNAL);
|
||||
eina_mempool_del(ce->mp->mp.SPACER);
|
||||
eina_mempool_del(ce->mp->mp.SNAPSHOT);
|
||||
eina_mempool_del(ce->mp->mp.MESH_NODE);
|
||||
eina_mempool_del(ce->mp->mp.LIGHT);
|
||||
eina_mempool_del(ce->mp->mp.CAMERA);
|
||||
eina_mempool_del(ce->mp->mp.VECTOR);
|
||||
eina_mempool_del(ce->mp->mp.part);
|
||||
memset(&ce->mp->mp, 0, sizeof(ce->mp->mp));
|
||||
|
||||
eina_mempool_del(ce->mp->mp_rtl.RECTANGLE);
|
||||
eina_mempool_del(ce->mp->mp_rtl.TEXT);
|
||||
eina_mempool_del(ce->mp->mp_rtl.IMAGE);
|
||||
eina_mempool_del(ce->mp->mp_rtl.PROXY);
|
||||
eina_mempool_del(ce->mp->mp_rtl.SWALLOW);
|
||||
eina_mempool_del(ce->mp->mp_rtl.TEXTBLOCK);
|
||||
eina_mempool_del(ce->mp->mp_rtl.GROUP);
|
||||
eina_mempool_del(ce->mp->mp_rtl.BOX);
|
||||
eina_mempool_del(ce->mp->mp_rtl.TABLE);
|
||||
eina_mempool_del(ce->mp->mp_rtl.EXTERNAL);
|
||||
eina_mempool_del(ce->mp->mp_rtl.SPACER);
|
||||
eina_mempool_del(ce->mp->mp_rtl.SNAPSHOT);
|
||||
eina_mempool_del(ce->mp->mp_rtl.MESH_NODE);
|
||||
eina_mempool_del(ce->mp->mp_rtl.LIGHT);
|
||||
eina_mempool_del(ce->mp->mp_rtl.CAMERA);
|
||||
memset(&ce->mp->mp_rtl, 0, sizeof(ce->mp->mp_rtl));
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
@ -381,7 +381,7 @@ _edje_get_description_by_orientation(Edje *ed, Edje_Part_Description_Common *src
|
|||
case EDJE_PART_TYPE_##Short: \
|
||||
{ \
|
||||
Edje_Part_Description_##Type * Name; \
|
||||
Name = eina_mempool_malloc(ce->mp_rtl.Short, \
|
||||
Name = eina_mempool_malloc(ce->mp->mp_rtl.Short, \
|
||||
sizeof (Edje_Part_Description_##Type)); \
|
||||
desc_rtl = &Name->common; \
|
||||
memsize = sizeof(Edje_Part_Description_##Type); \
|
||||
|
@ -393,35 +393,35 @@ case EDJE_PART_TYPE_##Short: \
|
|||
switch (type)
|
||||
{
|
||||
case EDJE_PART_TYPE_RECTANGLE:
|
||||
desc_rtl = eina_mempool_malloc(ce->mp_rtl.RECTANGLE,
|
||||
desc_rtl = eina_mempool_malloc(ce->mp->mp_rtl.RECTANGLE,
|
||||
sizeof (Edje_Part_Description_Common));
|
||||
ce->count.RECTANGLE++;
|
||||
memsize = sizeof(Edje_Part_Description_Common);
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_SNAPSHOT:
|
||||
desc_rtl = eina_mempool_malloc(ce->mp_rtl.SNAPSHOT,
|
||||
desc_rtl = eina_mempool_malloc(ce->mp->mp_rtl.SNAPSHOT,
|
||||
sizeof (Edje_Part_Description_Snapshot));
|
||||
ce->count.SNAPSHOT++;
|
||||
memsize = sizeof(Edje_Part_Description_Snapshot);
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_SWALLOW:
|
||||
desc_rtl = eina_mempool_malloc(ce->mp_rtl.SWALLOW,
|
||||
desc_rtl = eina_mempool_malloc(ce->mp->mp_rtl.SWALLOW,
|
||||
sizeof (Edje_Part_Description_Common));
|
||||
ce->count.SWALLOW++;
|
||||
memsize = sizeof(Edje_Part_Description_Common);
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_GROUP:
|
||||
desc_rtl = eina_mempool_malloc(ce->mp_rtl.GROUP,
|
||||
desc_rtl = eina_mempool_malloc(ce->mp->mp_rtl.GROUP,
|
||||
sizeof (Edje_Part_Description_Common));
|
||||
ce->count.GROUP++;
|
||||
memsize = sizeof(Edje_Part_Description_Common);
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_SPACER:
|
||||
desc_rtl = eina_mempool_malloc(ce->mp_rtl.SPACER,
|
||||
desc_rtl = eina_mempool_malloc(ce->mp->mp_rtl.SPACER,
|
||||
sizeof (Edje_Part_Description_Common));
|
||||
ce->count.SPACER++;
|
||||
memsize = sizeof(Edje_Part_Description_Common);
|
||||
|
|
|
@ -1600,9 +1600,9 @@ static void
|
|||
_mempools_add(Edje_Part_Collection_Directory_Entry *de)
|
||||
{
|
||||
#define EDIT_EMN(Tp, Sz, Ce) \
|
||||
Ce->mp.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
|
||||
Ce->mp->mp.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
|
||||
#define EDIT_EMNP(Tp, Sz, Ce) \
|
||||
Ce->mp_rtl.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
|
||||
Ce->mp->mp_rtl.Tp = eina_mempool_add("chained_mempool", #Tp, NULL, sizeof (Sz), 8);
|
||||
|
||||
EDIT_EMN(RECTANGLE, Edje_Part_Description_Common, de);
|
||||
EDIT_EMN(TEXT, Edje_Part_Description_Text, de);
|
||||
|
@ -3081,7 +3081,7 @@ _edje_edit_real_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type
|
|||
ce = eina_hash_find(ed->file->collection, ed->group);
|
||||
|
||||
/* Alloc Edje_Part or return */
|
||||
ep = eina_mempool_malloc(ce->mp.part, sizeof(Edje_Part));
|
||||
ep = eina_mempool_malloc(ce->mp->mp.part, sizeof(Edje_Part));
|
||||
if (!ep) return EINA_FALSE;
|
||||
memset(ep, 0, sizeof(Edje_Part));
|
||||
|
||||
|
@ -3089,7 +3089,7 @@ _edje_edit_real_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type
|
|||
rp = eina_mempool_malloc(_edje_real_part_mp, sizeof(Edje_Real_Part));
|
||||
if (!rp)
|
||||
{
|
||||
eina_mempool_free(ce->mp.part, ep);
|
||||
eina_mempool_free(ce->mp->mp.part, ep);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
memset(rp, 0, sizeof(Edje_Real_Part));
|
||||
|
@ -3100,7 +3100,7 @@ _edje_edit_real_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type
|
|||
tmp = realloc(pc->parts, (pc->parts_count + 1) * sizeof (Edje_Part *));
|
||||
if (!tmp)
|
||||
{
|
||||
eina_mempool_free(ce->mp.part, ep);
|
||||
eina_mempool_free(ce->mp->mp.part, ep);
|
||||
eina_mempool_free(_edje_real_part_mp, rp);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
@ -3241,7 +3241,7 @@ _edje_edit_real_part_add(Evas_Object *obj, const char *name, Edje_Part_Type type
|
|||
_edje_if_string_free(ed, &ep->name);
|
||||
if (source)
|
||||
_edje_if_string_free(ed, &ep->source);
|
||||
eina_mempool_free(ce->mp.part, ep);
|
||||
eina_mempool_free(ce->mp->mp.part, ep);
|
||||
eina_mempool_free(_edje_real_part_mp, rp);
|
||||
return EINA_FALSE;
|
||||
}
|
||||
|
@ -3347,7 +3347,7 @@ edje_edit_part_del(Evas_Object *obj, const char *part)
|
|||
_edje_collection_free_part_description_free(ep->type, ep->other.desc[k], ce, 0);
|
||||
|
||||
free(ep->other.desc);
|
||||
eina_mempool_free(ce->mp.part, ep);
|
||||
eina_mempool_free(ce->mp->mp.part, ep);
|
||||
|
||||
/* Free Edje_Real_Part */
|
||||
_edje_real_part_free(ed, rp);
|
||||
|
@ -6197,22 +6197,22 @@ _edje_edit_state_alloc(int type, Edje *ed)
|
|||
switch (type)
|
||||
{
|
||||
case EDJE_PART_TYPE_RECTANGLE:
|
||||
pd = eina_mempool_malloc(ce->mp.RECTANGLE, sizeof (Edje_Part_Description_Common));
|
||||
pd = eina_mempool_malloc(ce->mp->mp.RECTANGLE, sizeof (Edje_Part_Description_Common));
|
||||
ce->count.RECTANGLE++;
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_SPACER:
|
||||
pd = eina_mempool_malloc(ce->mp.SPACER, sizeof (Edje_Part_Description_Common));
|
||||
pd = eina_mempool_malloc(ce->mp->mp.SPACER, sizeof (Edje_Part_Description_Common));
|
||||
ce->count.SPACER++;
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_SWALLOW:
|
||||
pd = eina_mempool_malloc(ce->mp.SWALLOW, sizeof (Edje_Part_Description_Common));
|
||||
pd = eina_mempool_malloc(ce->mp->mp.SWALLOW, sizeof (Edje_Part_Description_Common));
|
||||
ce->count.SWALLOW++;
|
||||
break;
|
||||
|
||||
case EDJE_PART_TYPE_GROUP:
|
||||
pd = eina_mempool_malloc(ce->mp.GROUP, sizeof (Edje_Part_Description_Common));
|
||||
pd = eina_mempool_malloc(ce->mp->mp.GROUP, sizeof (Edje_Part_Description_Common));
|
||||
ce->count.GROUP++;
|
||||
break;
|
||||
|
||||
|
@ -6221,7 +6221,7 @@ case EDJE_PART_TYPE_##Short: \
|
|||
{ \
|
||||
Edje_Part_Description_##Type * Name; \
|
||||
\
|
||||
Name = eina_mempool_malloc(ce->mp.Short, \
|
||||
Name = eina_mempool_malloc(ce->mp->mp.Short, \
|
||||
sizeof (Edje_Part_Description_##Type)); \
|
||||
memset(Name, 0, sizeof(Edje_Part_Description_##Type)); \
|
||||
pd = &Name->common; \
|
||||
|
|
|
@ -2035,7 +2035,7 @@ _edje_collection_free(Edje_File *edf, Edje_Part_Collection *ec, Edje_Part_Collec
|
|||
// technically need this - but we ASSUME we use "one_big" so everything gets
|
||||
// freed in one go lower down when we del the mempool... but what if pool goes
|
||||
// "over"?
|
||||
eina_mempool_free(ce->mp.part, ep);
|
||||
eina_mempool_free(ce->mp->mp.part, ep);
|
||||
}
|
||||
free(ec->parts);
|
||||
ec->parts = NULL;
|
||||
|
@ -2141,9 +2141,9 @@ _edje_collection_free_part_description_free(int type,
|
|||
Edje_Part_Collection_Directory_Entry *ce,
|
||||
Eina_Bool free_strings)
|
||||
{
|
||||
#define FREE_POOL(Type, Ce, Desc) \
|
||||
case EDJE_PART_TYPE_##Type: eina_mempool_free(Ce->mp.Type, Desc); \
|
||||
ce->count.Type--; \
|
||||
#define FREE_POOL(Type, Ce, Desc) \
|
||||
case EDJE_PART_TYPE_##Type: eina_mempool_free(ce->mp->mp.Type, Desc); \
|
||||
ce->count.Type--; \
|
||||
break;
|
||||
|
||||
_edje_collection_free_part_description_clean(type, desc, free_strings);
|
||||
|
|
|
@ -884,19 +884,10 @@ struct _Edje_Limit
|
|||
TYPE SNAPSHOT; \
|
||||
TYPE VECTOR;
|
||||
|
||||
struct _Edje_Part_Collection_Directory_Entry
|
||||
typedef struct _Edje_Part_Collection_Directory_Entry_Mp Edje_Part_Collection_Directory_Entry_Mp;
|
||||
|
||||
struct _Edje_Part_Collection_Directory_Entry_Mp
|
||||
{
|
||||
const char *entry; /* the nominal name of the part collection */
|
||||
Edje_Part_Collection *ref;
|
||||
|
||||
struct
|
||||
{
|
||||
PART_TYPE_FIELDS(int)
|
||||
int part;
|
||||
} count;
|
||||
|
||||
int id; /* the id of this named part collection */
|
||||
|
||||
struct
|
||||
{
|
||||
PART_TYPE_FIELDS(Eina_Mempool *)
|
||||
|
@ -907,6 +898,22 @@ struct _Edje_Part_Collection_Directory_Entry
|
|||
{
|
||||
PART_TYPE_FIELDS(Eina_Mempool *)
|
||||
} mp_rtl; /* For Right To Left interface */
|
||||
};
|
||||
|
||||
struct _Edje_Part_Collection_Directory_Entry
|
||||
{
|
||||
const char *entry; /* the nominal name of the part collection */
|
||||
Edje_Part_Collection *ref;
|
||||
|
||||
Edje_Part_Collection_Directory_Entry_Mp *mp;
|
||||
|
||||
struct
|
||||
{
|
||||
PART_TYPE_FIELDS(int)
|
||||
int part;
|
||||
} count;
|
||||
|
||||
int id; /* the id of this named part collection */
|
||||
|
||||
Eina_Bool group_alias;
|
||||
};
|
||||
|
|
Loading…
Reference in New Issue