edje - save memory on edje parts as a lot of over-allocation was done

so ... Edje_Calc_Params was huge ... like about 200 bytes. every part
in every live edje object got one of these in addtion to real part
struct info etc. ... so really every part was probably consuming
300-500 bytes or so... crazy. so i made a lot of the data now optional
so only the minimum required is allocated now which cuts down about 110
or even 120 bytes per part, depending. 100 bytes was needed for 3d
node parts even though almsot no parts are 3d node parts... the image
and text data was 30-40 bytes so we consumed 100 even if we only used
30-40... so this cuts that done and puts in polace calc param cleanup
funcs everywhere they are needed to clean up this extra allocated data.

i also reduced this even more by maping pointers to req_drag, map and
physics and clip_to fields in another extension struct cutting
down another 28/52 bytes on most parts (in  return for an added
4/8 bytes - on 32/64bit accordingly).

in elementary_test this saves about ~300kb of ram for just having the
etst run and displaying (peak memory measuremment). so massif says
10.6M -> 10.3M.

@optimize
This commit is contained in:
Carsten Haitzler 2016-08-14 22:30:32 +09:00
parent a5232bb283
commit 1d6a58cfc9
6 changed files with 595 additions and 407 deletions

File diff suppressed because it is too large Load Diff

View File

@ -2123,11 +2123,6 @@ case EDJE_PART_TYPE_##Short: \
memset(rp->custom, 0, sizeof (Edje_Real_Part_State));
rp->custom->p.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
rp->custom->p.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
*d = *parent;
d->state.name = (char *)eina_stringshare_add("custom");

View File

@ -704,11 +704,6 @@ _edje_object_file_set_internal(Evas_Object *obj, const Eina_File *file, const ch
memset(rp, 0, sizeof (Edje_Real_Part));
rp->param1.p.map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
rp->param1.p.physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
if ((ep->dragable.x != 0) || (ep->dragable.y != 0))
{
rp->drag = calloc(1, sizeof (Edje_Real_Part_Drag));
@ -1724,9 +1719,8 @@ _edje_file_del(Edje *ed)
{
free(rp->param2->set);
rp->param2->set = NULL;
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->param2->p.map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->param2->p.physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(&(rp->param2->p));
#endif
}
eina_mempool_free(_edje_real_part_state_mp, rp->param2);
@ -1735,26 +1729,23 @@ _edje_file_del(Edje *ed)
{
free(rp->custom->set);
rp->custom->set = NULL;
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->custom->p.map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->custom->p.physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(&(rp->custom->p));
#endif
}
eina_mempool_free(_edje_real_part_state_mp, rp->custom);
if (rp->current)
{
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->current->map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->current->physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(rp->current);
#endif
free(rp->current);
rp->current = NULL;
}
_edje_unref(ed);
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->param1.p.map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->param1.p.physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(&(rp->param1.p));
#endif
eina_mempool_free(_edje_real_part_mp, rp);
ed->table_parts[i] = NULL;

View File

@ -1794,52 +1794,71 @@ struct _Edje_Calc_Params_Physics
unsigned char ignore_part_pos; //1
};
typedef struct _Edje_Calc_Params_Type_Common Edje_Calc_Params_Type_Common;
typedef struct _Edje_Calc_Params_Type_Text Edje_Calc_Params_Type_Text;
typedef struct _Edje_Calc_Params_Type_Node Edje_Calc_Params_Type_Node;
struct _Edje_Calc_Params_Type_Common
{
struct {
int x, y, w, h; // 16
} fill; // 16
union {
struct {
unsigned short l, r, t, b; // 8
FLOAT_T border_scale_by; // 8
} image; // 16
} spec; // 16
}; // 32
struct _Edje_Calc_Params_Type_Text
{
Edje_Alignment align; /* text alignment within bounds */ // 16
double ellipsis; // 8
int size; // 4
Edje_Color color2, color3; // 8
}; // 36
struct _Edje_Calc_Params_Type_Node
{
FLOAT_T data[6]; // 48
Edje_3D_Vec point; // 24
Edje_3D_Vec scale_3d; // 24
int frame; // 4
}; // 100
typedef struct _Edje_Calc_Params_Ext Edje_Calc_Params_Ext;
struct _Edje_Calc_Params_Ext
{
Edje_Rectangle req_drag; // 16
const Edje_Calc_Params_Map *map; // 4/8
#ifdef HAVE_EPHYSICS
const Edje_Calc_Params_Physics *physics; // 4/8
#endif
Edje_Real_Part *clip_to; /* clip override @since 1.15 */ // 4/8
};
struct _Edje_Calc_Params
{
union {
Edje_Calc_Params_Type_Common *common;
Edje_Calc_Params_Type_Text *text;
Edje_Calc_Params_Type_Node *node;
} type; // 4/8
Edje_Calc_Params_Ext *ext; // 4/8
struct {
FLOAT_T x, y, w, h; // 32
} eval;
Edje_Rectangle final; // 16
Edje_Rectangle req; // 16
Edje_Rectangle req_drag; // 16
Edje_Color color; // 4
union {
struct {
struct {
int x, y, w, h; // 16
} fill; // 16
union {
struct {
unsigned short l, r, t, b; // 8
FLOAT_T border_scale_by; // 8
} image; // 16
} spec; // 16
} common; // 32
struct {
Edje_Alignment align; /* text alignment within bounds */ // 16
double ellipsis; // 8
int size; // 4
Edje_Color color2, color3; // 8
} text; // 36
struct {
FLOAT_T data[6]; // 48
Edje_3D_Vec point; // 24
Edje_3D_Vec scale_3d; // 24
int frame; // 4
} node; // 100
} type; // 100
const Edje_Calc_Params_Map *map; // 4/8
#ifdef HAVE_EPHYSICS
const Edje_Calc_Params_Physics *physics; // 4/8
#endif
Edje_Real_Part *clip_to; /* state clip override @since 1.15 */ // 4/8
unsigned char persp_on : 1;
unsigned char lighted : 1;
unsigned char mapped : 1;
unsigned char visible : 1;
unsigned char smooth : 1; // 1
}; // 197/209(rounded up for alignment: 200/212)
}; // 77/85(rounded up for alignment: 80/88)
struct _Edje_Real_Part_Set
{
@ -2321,6 +2340,42 @@ EAPI extern Eina_Mempool *_emp_SNAPSHOT;
EAPI extern Eina_Mempool *_emp_part;
EAPI extern Eina_Mempool *_emp_VECTOR;
static inline void
_edje_calc_params_need_type_common(Edje_Calc_Params *p)
{
if (p->type.common) return;
p->type.common = calloc(1, sizeof(Edje_Calc_Params_Type_Common));
}
static inline void
_edje_calc_params_need_type_text(Edje_Calc_Params *p)
{
if (p->type.text) return;
p->type.text = calloc(1, sizeof(Edje_Calc_Params_Type_Text));
}
static inline void
_edje_calc_params_need_type_node(Edje_Calc_Params *p)
{
if (p->type.node) return;
p->type.node = calloc(1, sizeof(Edje_Calc_Params_Type_Node));
}
static inline void
_edje_calc_params_need_ext(Edje_Calc_Params *p)
{
if (p->ext) return;
p->ext = calloc(1, sizeof(Edje_Calc_Params_Ext));
if (!p->ext) return;
#ifdef EDJE_CALC_CACHE
p->ext->map = eina_cow_alloc(_edje_calc_params_map_cow);
# ifdef HAVE_EPHYSICS
p->ext->physics = eina_cow_alloc(_edje_calc_params_physics_cow);
# endif
#endif
}
void _edje_calc_params_clear(Edje_Calc_Params *p);
void _edje_part_pos_set(Edje *ed, Edje_Real_Part *ep, int mode, FLOAT_T pos, FLOAT_T v1, FLOAT_T v2, FLOAT_T v3, FLOAT_T v4);
/** Find the description of the part by state name and state value.

View File

@ -681,17 +681,12 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig,
tmp = calloc(1, sizeof(Edje_Calc_Params));
if (!tmp) goto low_mem_current;
tmp->map = eina_cow_alloc(_edje_calc_params_map_cow);
#ifdef HAVE_EPHYSICS
tmp->physics = eina_cow_alloc(_edje_calc_params_physics_cow);
#endif
_edje_part_recalc(ed, rp, FLAG_XY, tmp);
if (rp->current)
{
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->current->map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->current->physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(rp->current);
#endif
free(rp->current);
}
@ -702,9 +697,8 @@ _edje_program_run(Edje *ed, Edje_Program *pr, Eina_Bool force, const char *ssig,
low_mem_current:
if (rp->current)
{
eina_cow_free(_edje_calc_params_map_cow, (const Eina_Cow_Data **)&rp->current->map);
#ifdef HAVE_EPHYSICS
eina_cow_free(_edje_calc_params_physics_cow, (const Eina_Cow_Data **)&rp->current->physics);
#ifdef EDJE_CALC_CACHE
_edje_calc_params_clear(rp->current);
#endif
free(rp->current);
}

View File

@ -130,12 +130,13 @@ _edje_text_fit_x(Edje *ed, Edje_Real_Part *ep,
*free_text = 0;
if (sw <= 1) return "";
if ((params->type.text.ellipsis < 0) || (chosen_desc->text.min_x))
_edje_calc_params_need_type_text(params);
if ((params->type.text->ellipsis < 0) || (chosen_desc->text.min_x))
return text;
if (ep->part->scale) evas_object_scale_set(ep->object, TO_DOUBLE(sc));
evas_obj_text_ellipsis_set(ep->object, params->type.text.ellipsis);
evas_obj_text_ellipsis_set(ep->object, params->type.text->ellipsis);
efl_text_properties_font_set(ep->object, font, size);
efl_text_set(ep->object, text);
efl_gfx_size_set(ep->object, sw, sh);
@ -293,8 +294,9 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
sw = TO_INT(params->eval.w);
sh = TO_INT(params->eval.h);
if (params->type.text.size)
size = params->type.text.size;
_edje_calc_params_need_type_text(params);
if (params->type.text->size)
size = params->type.text->size;
if (!text) text = "";
if ((text == ep->typedata.text->cache.in_str)
@ -309,9 +311,9 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
(ep->typedata.text->cache.in_h == sh) &&
(ep->typedata.text->cache.in_str) &&
same_text &&
(ep->typedata.text->cache.align_x == params->type.text.align.x) &&
(ep->typedata.text->cache.align_y == params->type.text.align.y) &&
(ep->typedata.text->cache.ellipsis == params->type.text.ellipsis) &&
(ep->typedata.text->cache.align_x == params->type.text->align.x) &&
(ep->typedata.text->cache.align_y == params->type.text->align.y) &&
(ep->typedata.text->cache.ellipsis == params->type.text->ellipsis) &&
(ep->typedata.text->cache.fit_x == chosen_desc->text.fit_x) &&
(ep->typedata.text->cache.fit_y == chosen_desc->text.fit_y) &&
(ep->typedata.text->cache.in_font == font))
@ -465,7 +467,7 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
else if ((ed->file->version >= 3) && (ed->file->minor >= 6))
{
evas_object_text_ellipsis_set(ep->object,
params->type.text.ellipsis);
params->type.text->ellipsis);
}
eina_stringshare_replace(&ep->typedata.text->cache.out_str, text);
@ -473,9 +475,9 @@ _edje_text_recalc_apply(Edje *ed, Edje_Real_Part *ep,
ep->typedata.text->cache.in_h = sh;
ep->typedata.text->cache.in_font = font;
ep->typedata.text->cache.out_size = size;
ep->typedata.text->cache.align_x = params->type.text.align.x;
ep->typedata.text->cache.align_y = params->type.text.align.y;
ep->typedata.text->cache.ellipsis = params->type.text.ellipsis;
ep->typedata.text->cache.align_x = params->type.text->align.x;
ep->typedata.text->cache.align_y = params->type.text->align.y;
ep->typedata.text->cache.ellipsis = params->type.text->ellipsis;
ep->typedata.text->cache.fit_x = chosen_desc->text.fit_x;
ep->typedata.text->cache.fit_y = chosen_desc->text.fit_y;
arrange_text:
@ -492,7 +494,7 @@ arrange_text:
/* Handle alignment */
{
FLOAT_T align_x;
if (params->type.text.align.x < FROM_INT(0))
if (params->type.text->align.x < FROM_INT(0))
{
if (evas_object_text_direction_get(ep->object) ==
EVAS_BIDI_DIRECTION_RTL)
@ -506,10 +508,10 @@ arrange_text:
}
else
{
align_x = params->type.text.align.x;
align_x = params->type.text->align.x;
}
ep->typedata.text->offset.x = TO_INT(SCALE(align_x, (sw - tw)));
ep->typedata.text->offset.y = TO_INT(SCALE(params->type.text.align.y, (sh - th)));
ep->typedata.text->offset.y = TO_INT(SCALE(params->type.text->align.y, (sh - th)));
}
if (!calc_only)
@ -540,73 +542,73 @@ arrange_text:
case EDJE_TEXT_EFFECT_OUTLINE:
style = EVAS_TEXT_STYLE_OUTLINE;
evas_object_text_outline_color_set(ep->object,
(params->type.text.color2.r * params->type.text.color2.a) / 255,
(params->type.text.color2.g * params->type.text.color2.a) / 255,
(params->type.text.color2.b * params->type.text.color2.a) / 255,
params->type.text.color2.a);
(params->type.text->color2.r * params->type.text->color2.a) / 255,
(params->type.text->color2.g * params->type.text->color2.a) / 255,
(params->type.text->color2.b * params->type.text->color2.a) / 255,
params->type.text->color2.a);
break;
case EDJE_TEXT_EFFECT_SOFT_OUTLINE:
style = EVAS_TEXT_STYLE_SOFT_OUTLINE;
evas_object_text_outline_color_set(ep->object,
(params->type.text.color2.r * params->type.text.color2.a) / 255,
(params->type.text.color2.g * params->type.text.color2.a) / 255,
(params->type.text.color2.b * params->type.text.color2.a) / 255,
params->type.text.color2.a);
(params->type.text->color2.r * params->type.text->color2.a) / 255,
(params->type.text->color2.g * params->type.text->color2.a) / 255,
(params->type.text->color2.b * params->type.text->color2.a) / 255,
params->type.text->color2.a);
break;
case EDJE_TEXT_EFFECT_SHADOW:
style = EVAS_TEXT_STYLE_SHADOW;
evas_object_text_shadow_color_set(ep->object,
(params->type.text.color3.r * params->type.text.color3.a) / 255,
(params->type.text.color3.g * params->type.text.color3.a) / 255,
(params->type.text.color3.b * params->type.text.color3.a) / 255,
params->type.text.color3.a);
(params->type.text->color3.r * params->type.text->color3.a) / 255,
(params->type.text->color3.g * params->type.text->color3.a) / 255,
(params->type.text->color3.b * params->type.text->color3.a) / 255,
params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_SOFT_SHADOW:
style = EVAS_TEXT_STYLE_SOFT_SHADOW;
evas_object_text_shadow_color_set(ep->object,
(params->type.text.color3.r * params->type.text.color3.a) / 255,
(params->type.text.color3.g * params->type.text.color3.a) / 255,
(params->type.text.color3.b * params->type.text.color3.a) / 255,
params->type.text.color3.a);
(params->type.text->color3.r * params->type.text->color3.a) / 255,
(params->type.text->color3.g * params->type.text->color3.a) / 255,
(params->type.text->color3.b * params->type.text->color3.a) / 255,
params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_OUTLINE_SHADOW:
style = EVAS_TEXT_STYLE_OUTLINE_SHADOW;
evas_obj_text_outline_color_set(ep->object, (params->type.text.color2.r * params->type.text.color2.a) / 255, (params->type.text.color2.g * params->type.text.color2.a) / 255, (params->type.text.color2.b * params->type.text.color2.a) / 255, params->type.text.color2.a);
evas_obj_text_shadow_color_set(ep->object, (params->type.text.color3.r * params->type.text.color3.a) / 255, (params->type.text.color3.g * params->type.text.color3.a) / 255, (params->type.text.color3.b * params->type.text.color3.a) / 255, params->type.text.color3.a);
evas_obj_text_outline_color_set(ep->object, (params->type.text->color2.r * params->type.text->color2.a) / 255, (params->type.text->color2.g * params->type.text->color2.a) / 255, (params->type.text->color2.b * params->type.text->color2.a) / 255, params->type.text->color2.a);
evas_obj_text_shadow_color_set(ep->object, (params->type.text->color3.r * params->type.text->color3.a) / 255, (params->type.text->color3.g * params->type.text->color3.a) / 255, (params->type.text->color3.b * params->type.text->color3.a) / 255, params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_OUTLINE_SOFT_SHADOW:
style = EVAS_TEXT_STYLE_OUTLINE_SOFT_SHADOW;
evas_obj_text_outline_color_set(ep->object, (params->type.text.color2.r * params->type.text.color2.a) / 255, (params->type.text.color2.g * params->type.text.color2.a) / 255, (params->type.text.color2.b * params->type.text.color2.a) / 255, params->type.text.color2.a);
evas_obj_text_shadow_color_set(ep->object, (params->type.text.color3.r * params->type.text.color3.a) / 255, (params->type.text.color3.g * params->type.text.color3.a) / 255, (params->type.text.color3.b * params->type.text.color3.a) / 255, params->type.text.color3.a);
evas_obj_text_outline_color_set(ep->object, (params->type.text->color2.r * params->type.text->color2.a) / 255, (params->type.text->color2.g * params->type.text->color2.a) / 255, (params->type.text->color2.b * params->type.text->color2.a) / 255, params->type.text->color2.a);
evas_obj_text_shadow_color_set(ep->object, (params->type.text->color3.r * params->type.text->color3.a) / 255, (params->type.text->color3.g * params->type.text->color3.a) / 255, (params->type.text->color3.b * params->type.text->color3.a) / 255, params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_FAR_SHADOW:
style = EVAS_TEXT_STYLE_FAR_SHADOW;
evas_object_text_shadow_color_set(ep->object,
(params->type.text.color3.r * params->type.text.color3.a) / 255,
(params->type.text.color3.g * params->type.text.color3.a) / 255,
(params->type.text.color3.b * params->type.text.color3.a) / 255,
params->type.text.color3.a);
(params->type.text->color3.r * params->type.text->color3.a) / 255,
(params->type.text->color3.g * params->type.text->color3.a) / 255,
(params->type.text->color3.b * params->type.text->color3.a) / 255,
params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_FAR_SOFT_SHADOW:
style = EVAS_TEXT_STYLE_FAR_SOFT_SHADOW;
evas_object_text_shadow_color_set(ep->object,
(params->type.text.color3.r * params->type.text.color3.a) / 255,
(params->type.text.color3.g * params->type.text.color3.a) / 255,
(params->type.text.color3.b * params->type.text.color3.a) / 255,
params->type.text.color3.a);
(params->type.text->color3.r * params->type.text->color3.a) / 255,
(params->type.text->color3.g * params->type.text->color3.a) / 255,
(params->type.text->color3.b * params->type.text->color3.a) / 255,
params->type.text->color3.a);
break;
case EDJE_TEXT_EFFECT_GLOW:
style = EVAS_TEXT_STYLE_GLOW;
evas_obj_text_glow_color_set(ep->object, (params->type.text.color2.r * params->type.text.color2.a) / 255, (params->type.text.color2.g * params->type.text.color2.a) / 255, (params->type.text.color2.b * params->type.text.color2.a) / 255, params->type.text.color2.a);
evas_obj_text_glow2_color_set(ep->object, (params->type.text.color3.r * params->type.text.color3.a) / 255, (params->type.text.color3.g * params->type.text.color3.a) / 255, (params->type.text.color3.b * params->type.text.color3.a) / 255, params->type.text.color3.a);
evas_obj_text_glow_color_set(ep->object, (params->type.text->color2.r * params->type.text->color2.a) / 255, (params->type.text->color2.g * params->type.text->color2.a) / 255, (params->type.text->color2.b * params->type.text->color2.a) / 255, params->type.text->color2.a);
evas_obj_text_glow2_color_set(ep->object, (params->type.text->color3.r * params->type.text->color3.a) / 255, (params->type.text->color3.g * params->type.text->color3.a) / 255, (params->type.text->color3.b * params->type.text->color3.a) / 255, params->type.text->color3.a);
break;
default: