From e4d815dc48c660a336670ec3cc67e6becbdcacfc Mon Sep 17 00:00:00 2001 From: "Carsten Haitzler (Rasterman)" Date: Fri, 22 Apr 2016 12:03:25 +0900 Subject: [PATCH] efreetd - reduce memory usage by using stringshare much more lots of long paths for monitoring file paths for icons etc. are in memory for efreetd. this reduces that memory by sharing them much more. @optimization --- src/bin/efreet/efreetd_cache.c | 12 ++++++------ src/examples/elementary/codegen_example.edj | Bin 12063 -> 0 bytes src/lib/ecore_file/ecore_file_monitor_inotify.c | 13 +++++++------ src/lib/ecore_file/ecore_file_monitor_poll.c | 13 +++++++------ src/lib/ecore_file/ecore_file_monitor_win32.c | 20 ++++++++------------ src/lib/ecore_file/ecore_file_private.h | 2 +- 6 files changed, 29 insertions(+), 31 deletions(-) delete mode 100644 src/examples/elementary/codegen_example.edj diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c index fefc852..9e8444f 100644 --- a/src/bin/efreet/efreetd_cache.c +++ b/src/bin/efreet/efreetd_cache.c @@ -89,7 +89,7 @@ subdir_cache_dir_free(Subdir_Cache_Dir *cd) static void * subdir_cache_hash_add(void *hash, const char *key, void *data) { - if (!hash) hash = eina_hash_string_superfast_new(EINA_FREE_CB(subdir_cache_dir_free)); + if (!hash) hash = eina_hash_stringshared_new(EINA_FREE_CB(subdir_cache_dir_free)); if (!hash) return NULL; eina_hash_add(hash, key, data); return hash; @@ -140,7 +140,7 @@ subdir_cache_init(void) // if we don't have a hash in the subdir cache - allocate it if (!subdir_cache->dirs) - subdir_cache->dirs = eina_hash_string_superfast_new(EINA_FREE_CB(subdir_cache_dir_free)); + subdir_cache->dirs = eina_hash_stringshared_new(EINA_FREE_CB(subdir_cache_dir_free)); } static void @@ -303,7 +303,7 @@ icon_cache_update_cache_cb(void *data EINA_UNUSED) if ((!icon_flush) && (!icon_exts)) return ECORE_CALLBACK_CANCEL; if (icon_change_monitors) eina_hash_free(icon_change_monitors); - icon_change_monitors = eina_hash_string_superfast_new + icon_change_monitors = eina_hash_stringshared_new (EINA_FREE_CB(ecore_file_monitor_del)); icon_changes_listen(); subdir_cache_save(); @@ -360,7 +360,7 @@ desktop_cache_update_cache_cb(void *data EINA_UNUSED) desktop_queue = EINA_FALSE; if (desktop_change_monitors) eina_hash_free(desktop_change_monitors); - desktop_change_monitors = eina_hash_string_superfast_new + desktop_change_monitors = eina_hash_stringshared_new (EINA_FREE_CB(ecore_file_monitor_del)); desktop_changes_listen(); subdir_cache_save(); @@ -867,9 +867,9 @@ cache_init(void) goto error; } - icon_change_monitors = eina_hash_string_superfast_new + icon_change_monitors = eina_hash_stringshared_new (EINA_FREE_CB(ecore_file_monitor_del)); - desktop_change_monitors = eina_hash_string_superfast_new + desktop_change_monitors = eina_hash_stringshared_new (EINA_FREE_CB(ecore_file_monitor_del)); efreet_cache_update = 0; diff --git a/src/examples/elementary/codegen_example.edj b/src/examples/elementary/codegen_example.edj deleted file mode 100644 index 4f87ec8c821cfc0400313182b74892f719989cdb..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 12063 zcmaKw2Ut``*T*j^DpAqc0O{2NE{ev6uLc1@6tHV7+4r)0Sys2XyL2^bP&D?M1bf4v zMq^8iB@#uA4b&J5YHU%l5bQ`m{r+?Bon_#8^WDecocZ0kQ_h@oW>$}fP5W^iSC8ZD z{5dXQHuT0)aT*NS5(Q7dHyl^zImb0R#&J$+fF>vdIIjI7$Qk%{7x*OTA4$A}GsoFC z;J6OA!85^HNSv#K`U2<;QMeCyAnd_bKsqoi0c#v~8)B(O7(?kM!z;b0}GHewj&=JXQv`qG!;w`0L7!0Iv#c66!& zYsP$go#ULz+}Lraf;oY)bKU^vTZ^TG1%o-F(D~Vc{RdTcj9y@|U~GSf!9D{c`$4~5 z2Bxaj4)2|fU`?5J*k5PNk!!-NEevdKt#%r)958k+*dOPuVC-CWfc;pjzn)<5r5bjD zUpN=m`t}xBF_=Fymo;Ey|Jb!1~W3$uoo`zq#X(!_ZiqoR9WB61N$6|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lib/ecore_file/ecore_file_monitor_inotify.c +++ b/src/lib/ecore_file/ecore_file_monitor_inotify.c @@ -107,7 +107,8 @@ ecore_file_monitor_backend_add(const char *path, void *data) { Ecore_File_Monitor *em; - int len; + char *path2; + size_t len; if (_inotify_fd_pid == -1) return NULL; @@ -123,10 +124,10 @@ ecore_file_monitor_backend_add(const char *path, em->func = func; em->data = data; - em->path = strdup(path); - len = strlen(em->path); - if (em->path[len - 1] == '/' && strcmp(em->path, "/")) - em->path[len - 1] = 0; + len = strlen(path); + path2 = alloca(len + 1); + if (path2[len - 1] == '/' && strcmp(path2, "/")) path2[len - 1] = 0; + em->path = eina_stringshare_add(path2); _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); @@ -149,7 +150,7 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em) fd = ecore_main_fd_handler_fd_get(_fdh); if (ECORE_FILE_MONITOR_INOTIFY(em)->wd) inotify_rm_watch(fd, ECORE_FILE_MONITOR_INOTIFY(em)->wd); - free(em->path); + eina_stringshare_del(em->path); free(em); } diff --git a/src/lib/ecore_file/ecore_file_monitor_poll.c b/src/lib/ecore_file/ecore_file_monitor_poll.c index 088787e..16f8419 100644 --- a/src/lib/ecore_file/ecore_file_monitor_poll.c +++ b/src/lib/ecore_file/ecore_file_monitor_poll.c @@ -68,6 +68,7 @@ ecore_file_monitor_backend_add(const char *path, void *data) { Ecore_File_Monitor *em; + char *path2; size_t len; if (!path) return NULL; @@ -81,14 +82,14 @@ ecore_file_monitor_backend_add(const char *path, else ecore_timer_interval_set(_timer, ECORE_FILE_INTERVAL_MIN); - em->path = strdup(path); - len = strlen(em->path); - if (em->path[len - 1] == '/' && strcmp(em->path, "/")) - em->path[len - 1] = 0; - em->func = func; em->data = data; + len = strlen(path); + path2 = alloca(len + 1); + if (path2[len - 1] == '/' && strcmp(path2, "/")) path2[len - 1] = 0; + em->path = eina_stringshare_add(path2); + ECORE_FILE_MONITOR_POLL(em)->mtime = ecore_file_mod_time(em->path); _monitors = ECORE_FILE_MONITOR(eina_inlist_append(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); @@ -160,7 +161,7 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em) if (_monitors) _monitors = ECORE_FILE_MONITOR(eina_inlist_remove(EINA_INLIST_GET(_monitors), EINA_INLIST_GET(em))); - free(em->path); + eina_stringshare_del(em->path); free(em); if (_timer) diff --git a/src/lib/ecore_file/ecore_file_monitor_win32.c b/src/lib/ecore_file/ecore_file_monitor_win32.c index f6186f6..20f2ad0 100644 --- a/src/lib/ecore_file/ecore_file_monitor_win32.c +++ b/src/lib/ecore_file/ecore_file_monitor_win32.c @@ -243,6 +243,7 @@ ecore_file_monitor_backend_add(const char *path, { Ecore_File_Monitor_Win32 *m; Ecore_File_Monitor *em; + char *path2; size_t len; if (!path || (*path == '\0')) return NULL; @@ -256,22 +257,17 @@ ecore_file_monitor_backend_add(const char *path, em->func = func; em->data = data; - em->path = strdup(path); - if (!em->path) - { - free(em); - return NULL; - } - len = strlen(em->path); - if (em->path[len - 1] == '/' || em->path[len - 1] == '\\') - em->path[len - 1] = '\0'; + len = strlen(path); + path2 = alloca(len + 1); + if (path2[len - 1] == '/' || path2[len - 1] == '\\') path2[len - 1] = 0; + em->path = eina_stringshare_add(path2); m = ECORE_FILE_MONITOR_WIN32(em); m->file = _ecore_file_monitor_win32_data_new(em, 0); if (!m->file) { - free(em->path); + eina_stringshare_del(em->path); free(em); return NULL; } @@ -280,7 +276,7 @@ ecore_file_monitor_backend_add(const char *path, if (!m->dir) { _ecore_file_monitor_win32_data_free(m->file); - free(em->path); + eina_stringshare_del(em->path); free(em); return NULL; } @@ -301,6 +297,6 @@ ecore_file_monitor_backend_del(Ecore_File_Monitor *em) m = ECORE_FILE_MONITOR_WIN32(em); _ecore_file_monitor_win32_data_free(m->dir); _ecore_file_monitor_win32_data_free(m->file); - free(em->path); + eina_stringshare_del(em->path); free(em); } diff --git a/src/lib/ecore_file/ecore_file_private.h b/src/lib/ecore_file/ecore_file_private.h index 82f9767..7c33ec8 100644 --- a/src/lib/ecore_file/ecore_file_private.h +++ b/src/lib/ecore_file/ecore_file_private.h @@ -76,7 +76,7 @@ struct _Ecore_File_Monitor Ecore_File_Event event, const char *path); - char *path; + const char *path; void *data; Ecore_File *files; }; -- 2.7.4