Object create time increase as total object number increases

Hi All,

I’m using the below function to create line object.
However I found out that the process time increase as the total object number increase.

line = lv_line_create(lv_disp_get_scr_act(g_disp[Chan][disp_count[Chan]]),NULL);

For example,
when I first create the line, it takes about 0.024ms to process lv_create_line()
However, when the total object number increase to 180, it takes about 0.087ms to create a line object.

May I know the reason?
Or Could someone guide me how to improve this?

Futhermore, I found out that
lv_obj_set_style_local_line_xxx has the same situation. (process time increase as total object number increase.)

The code block(s) should be formatted like:

void DrawLine(UINT32 Chan, UINT32 X1, UINT32 Y1, UINT32 X2, UINT32 Y2, UINT32 LineWidth, UINT32 Color, UINT32 *LineTotal)
{

    lv_obj_t * line;
    lv_color_t line_color;
    lv_point_t _point[2] = {{(lv_coord_t)X1,(lv_coord_t)Y1},{(lv_coord_t)X2,(lv_coord_t)Y2}};


    line_points[Chan][line_count[Chan]] = _point[0];
    line_points[Chan][line_count[Chan]+1U] = _point[1];
    
    line_color.full = Color;
   
    /* Measure time */
    line = lv_line_create(lv_disp_get_scr_act(g_disp[Chan][disp_count[Chan]]),NULL);
   /* Measure time */

    lv_obj_set_pos(line,0,0);

    lv_obj_add_style(line,LV_LINE_PART_MAIN,&style_line);

    lv_line_set_points(line,&line_points[Chan][line_count[Chan]],2U);

    lv_obj_set_style_local_line_color(line,LV_OBJ_PART_MAIN,LV_STATE_DEFAULT,line_color);

    lv_obj_set_style_local_line_width(line,LV_OBJ_PART_MAIN,LV_STATE_DEFAULT,(lv_coord_t)LineWidth);

    lv_obj_set_style_local_line_opa(line,LV_OBJ_PART_MAIN,LV_STATE_DEFAULT,Color>>24);
   

}

I’ve check further into the source code, and found out that it is void * lv_mem_alloc(size_t size) that takes most of the time.

Since I do not use custome malloc, therefore, the code flow should run below

#if LV_MEM_CUSTOM == 0
    /*Use the built-in allocators*/
    lv_mem_ent_t * e = NULL;

    /* Search for a appropriate entry*/
    do {
        /* Get the next entry*/
        e = ent_get_next(e);

        /*If there is next entry then try to allocate there*/
        if(e != NULL) {
            alloc = ent_alloc(e, size);
        }
        /* End if there is not next entry OR the alloc. is successful*/
    } while(e != NULL && alloc == NULL);

#else

I think it is because object is getting more and more, therefore, it takes more than to find next entry.

May I know is there a good solution to improve this?

Many Thanks for your help.

The heap implementation in v7 is definitely not perfect. If your platform has a better heap allocator, you can try using LV_MEM_CUSTOM and see if it helps performance.

However, even with your figures, it would only take 16ms to create 180 line objects. In my opinion, that’s a very acceptable speed.

Many Thanks for your reply.

I’ve check v8, and it’s heap implementation is different.
I wonder that if I only apply lv_mem.c and its related files (lv_tlsf.c) from v8 to v7, would it be possible?
Is there any side effect?

I observe that v8 changes a lot compared to v7.
It would take much effort to update my code base to v8.

It’d probably be faster to install standalone TLSF and configure it as the custom heap in lv_conf.h.