From c384f56e4f1a95a2fded43624c6f6c318b4fb9a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sat, 12 Aug 2017 20:04:37 -0300 Subject: [PATCH 1/3] Speed up playlist reparse --- menu/menu_entries.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/menu/menu_entries.c b/menu/menu_entries.c index 84755f68a3..5f5b3f6a56 100644 --- a/menu/menu_entries.c +++ b/menu/menu_entries.c @@ -448,7 +448,11 @@ void menu_entries_append_enum(file_list_t *list, const char *path, file_list_set_actiondata(list, idx, cbs); cbs->enum_idx = enum_idx; - cbs->setting = menu_setting_find_enum(enum_idx); + + if (enum_idx != MENU_ENUM_LABEL_PLAYLIST_ENTRY + && enum_idx != MENU_ENUM_LABEL_PLAYLIST_COLLECTION_ENTRY) { + cbs->setting = menu_setting_find_enum(enum_idx); + } menu_cbs_init(list, cbs, path, label, type, idx); } From 26a9648c4f311c8f37ae0b87f9cc1308297a8d2c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sat, 12 Aug 2017 21:21:10 -0300 Subject: [PATCH 2/3] (menu_animation) Detect when defrag is really needed --- menu/menu_animation.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/menu/menu_animation.c b/menu/menu_animation.c index 8b517fb2d7..ce6cfa17dc 100644 --- a/menu/menu_animation.c +++ b/menu/menu_animation.c @@ -44,6 +44,7 @@ struct tween struct menu_animation { struct tween *list; + bool need_defrag; size_t capacity; size_t size; @@ -459,6 +460,8 @@ bool menu_animation_push(menu_animation_ctx_entry_t *entry) *target = t; + anim.need_defrag = true; + return true; } @@ -486,6 +489,7 @@ static void menu_animation_defrag() } anim.first_dead = anim.size; + anim.need_defrag = false; } bool menu_animation_update(float delta_time) @@ -511,6 +515,7 @@ bool menu_animation_update(float delta_time) { *tween->subject = tween->target_value; tween->alive = false; + anim.need_defrag = true; if (tween->cb) tween->cb(); @@ -520,12 +525,14 @@ bool menu_animation_update(float delta_time) active_tweens += 1; } - if (active_tweens) + if (anim.need_defrag) menu_animation_defrag(); - else + + if (!active_tweens) { anim.size = 0; anim.first_dead = 0; + anim.need_defrag = false; return false; } @@ -663,6 +670,8 @@ bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data) if (i < anim.first_dead) anim.first_dead = i; + + anim.need_defrag = true; } } break; @@ -690,6 +699,7 @@ bool menu_animation_ctl(enum menu_animation_ctl_state state, void *data) anim.first_dead = i; killed++; + anim.need_defrag = true; break; } } From 950b77c0ca818880d70d36c62f286b12bd6a46f7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Higor=20Eur=C3=ADpedes?= Date: Sat, 12 Aug 2017 22:06:46 -0300 Subject: [PATCH 3/3] (xmb) Speed up xmb_list_insert() and xmb_deep_copy() a bit This replaces calloc() and memcpy() calls with custom functions to handle xmb_node_t allocation and copy optimized for the common case. --- menu/drivers/xmb.c | 46 +++++++++++++++++++++++++++++++++++++++------- 1 file changed, 39 insertions(+), 7 deletions(-) diff --git a/menu/drivers/xmb.c b/menu/drivers/xmb.c index f1ff6b54fc..7ac2fa4e02 100644 --- a/menu/drivers/xmb.c +++ b/menu/drivers/xmb.c @@ -73,6 +73,8 @@ #define XMB_DEBUG #endif +/* NOTE: If you change this you HAVE to update + * xmb_alloc_node() and xmb_copy_node() */ typedef struct { float alpha; @@ -407,6 +409,40 @@ const char* xmb_theme_ident(void) return "monochrome"; } +/* NOTE: This exists because calloc()ing xmb_node_t is expensive + * when you can have big lists like MAME and fba playlists */ +static xmb_node_t *xmb_alloc_node(void) +{ + xmb_node_t *node = (xmb_node_t*)malloc(sizeof(*node)); + + node->alpha = node->label_alpha = 0; + node->zoom = node->x = node->y = 0; + node->icon = node->content_icon = 0; + node->fullpath[0] = 0; + + return node; +} + +/* NOTE: This is faster than memcpy()ing xmb_node_t in most cases + * because most nodes have small (less than 200 bytes) fullpath */ +static xmb_node_t *xmb_copy_node(void *p) +{ + xmb_node_t *old_node = (xmb_node_t*)p; + xmb_node_t *new_node = (xmb_node_t*)malloc(sizeof(*new_node)); + + new_node->alpha = old_node->alpha; + new_node->label_alpha = old_node->label_alpha; + new_node->zoom = old_node->zoom; + new_node->x = old_node->x; + new_node->y = old_node->y; + new_node->icon = old_node->icon; + new_node->content_icon = old_node->content_icon; + + strlcpy(new_node->fullpath, old_node->fullpath, sizeof(old_node->fullpath)); + + return new_node; +} + static const char *xmb_thumbnails_ident(void) { settings_t *settings = config_get_ptr(); @@ -1354,7 +1390,7 @@ static void xmb_list_open_new(xmb_handle_t *xmb, static xmb_node_t *xmb_node_allocate_userdata(xmb_handle_t *xmb, unsigned i) { - xmb_node_t *node = (xmb_node_t*)calloc(1, sizeof(xmb_node_t)); + xmb_node_t *node = xmb_alloc_node(); if (!node) { @@ -3683,7 +3719,7 @@ static void xmb_list_insert(void *userdata, node = (xmb_node_t*)menu_entries_get_userdata_at_offset(list, i); if (!node) - node = (xmb_node_t*)calloc(1, sizeof(xmb_node_t)); + node = xmb_alloc_node(); if (!node) { @@ -3756,11 +3792,7 @@ static void xmb_list_deep_copy(const file_list_t *src, file_list_t *dst) void *src_adata = (void*)menu_entries_get_actiondata_at_offset(src, i); if (src_udata) - { - void *data = malloc(sizeof(xmb_node_t)); - memcpy(data, src_udata, sizeof(xmb_node_t)); - file_list_set_userdata(dst, i, data); - } + file_list_set_userdata(dst, i, xmb_copy_node(src_udata)); if (src_adata) {