summaryrefslogtreecommitdiff
path: root/src/bin/efreet/efreetd_cache.c
diff options
context:
space:
mode:
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-08-23 11:59:37 +0900
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>2016-08-23 12:04:06 +0900
commit561f8eaa8faebe32b9a03cf9674c147cf0d6d9ab (patch)
tree150e42dcb87333b146e884f6bf72dc5f561e7967 /src/bin/efreet/efreetd_cache.c
parent56c52311e5590543272b0465a750936475ad28e7 (diff)
efreet - save about 240-300k or so of memory used by efreet mime
so efreet mime was loading a bunch of mime type info files, parsing them on startup and allocating memory to store all this mime info - globs, mimetype strings and more. all a big waste of memory as its allocated on the heap per process where its the SAME data files loaded every time. so make an efreet mime cache file and a tool to create it from mime files. mmap this file with all the hashes/strings in it so all that data is mmaped once in memory and shared between all processes and it is only paged in on demand - as actually read/needed so if your process doesnt need to know about mime stuff.. it wont touch it anyway. this saves about 240-300k or so of memory in my tests. this has not covered the mime MAGIC files which still consume memory and are on the heap. this is more complex so it will take more time to come up with a nice file format for the data that is nicely mmaped etc. @optimize
Diffstat (limited to 'src/bin/efreet/efreetd_cache.c')
-rw-r--r--src/bin/efreet/efreetd_cache.c124
1 files changed, 124 insertions, 0 deletions
diff --git a/src/bin/efreet/efreetd_cache.c b/src/bin/efreet/efreetd_cache.c
index fefc852dd0..b1ef5e8b81 100644
--- a/src/bin/efreet/efreetd_cache.c
+++ b/src/bin/efreet/efreetd_cache.c
@@ -71,6 +71,13 @@ static Eet_Data_Descriptor *subdir_dir_edd = NULL;
71static Subdir_Cache *subdir_cache = NULL; 71static Subdir_Cache *subdir_cache = NULL;
72static Eina_Bool subdir_need_save = EINA_FALSE; 72static Eina_Bool subdir_need_save = EINA_FALSE;
73 73
74static Eina_Hash *mime_monitors = NULL;
75static Ecore_Timer *mime_update_timer = NULL;
76static Ecore_Exe *mime_cache_exe = NULL;
77
78static void mime_cache_init(void);
79static void mime_cache_shutdown(void);
80
74static void 81static void
75subdir_cache_dir_free(Subdir_Cache_Dir *cd) 82subdir_cache_dir_free(Subdir_Cache_Dir *cd)
76{ 83{
@@ -756,6 +763,10 @@ cache_exe_data_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
756 if ((ev->lines) && (*ev->lines->line == 'c')) update = EINA_TRUE; 763 if ((ev->lines) && (*ev->lines->line == 'c')) update = EINA_TRUE;
757 send_signal_icon_cache_update(update); 764 send_signal_icon_cache_update(update);
758 } 765 }
766 else if (ev->exe == mime_cache_exe)
767 {
768 // XXX: ZZZ: handle stdout here from cache updater... if needed
769 }
759 return ECORE_CALLBACK_RENEW; 770 return ECORE_CALLBACK_RENEW;
760} 771}
761 772
@@ -774,6 +785,11 @@ cache_exe_del_cb(void *data EINA_UNUSED, int type EINA_UNUSED, void *event)
774 icon_cache_exe = NULL; 785 icon_cache_exe = NULL;
775 if (icon_queue) cache_icon_update(EINA_FALSE); 786 if (icon_queue) cache_icon_update(EINA_FALSE);
776 } 787 }
788 else if (ev->exe == mime_cache_exe)
789 {
790 mime_cache_exe = NULL;
791 send_signal_mime_cache_build();
792 }
777 return ECORE_CALLBACK_RENEW; 793 return ECORE_CALLBACK_RENEW;
778} 794}
779 795
@@ -838,6 +854,111 @@ cache_desktop_exists(void)
838 return desktop_exists; 854 return desktop_exists;
839} 855}
840 856
857static void
858mime_update_launch(void)
859{
860 char file[PATH_MAX];
861
862 snprintf(file, sizeof(file),
863 "%s/efreet/" MODULE_ARCH "/efreet_mime_cache_create",
864 eina_prefix_lib_get(pfx));
865 mime_cache_exe = ecore_exe_pipe_run(file,
866 ECORE_EXE_PIPE_READ |
867 ECORE_EXE_PIPE_READ_LINE_BUFFERED,
868 NULL);
869}
870
871static Eina_Bool
872mime_update_cache_cb(void *data EINA_UNUSED)
873{
874 mime_update_timer = NULL;
875 if (mime_cache_exe)
876 {
877 ecore_exe_kill(mime_cache_exe);
878 ecore_exe_free(mime_cache_exe);
879 }
880 mime_update_launch();
881 return EINA_FALSE;
882}
883
884static void
885mime_changes_cb(void *data EINA_UNUSED, Ecore_File_Monitor *em EINA_UNUSED,
886 Ecore_File_Event event, const char *path EINA_UNUSED)
887{
888 switch (event)
889 {
890 case ECORE_FILE_EVENT_NONE:
891 /* noop */
892 break;
893
894 case ECORE_FILE_EVENT_CREATED_FILE:
895 case ECORE_FILE_EVENT_DELETED_FILE:
896 case ECORE_FILE_EVENT_MODIFIED:
897 case ECORE_FILE_EVENT_CLOSED:
898 case ECORE_FILE_EVENT_DELETED_DIRECTORY:
899 case ECORE_FILE_EVENT_CREATED_DIRECTORY:
900 case ECORE_FILE_EVENT_DELETED_SELF:
901 mime_cache_shutdown();
902 mime_cache_init();
903 if (mime_update_timer) ecore_timer_del(mime_update_timer);
904 mime_update_timer = ecore_timer_add(0.2, mime_update_cache_cb, NULL);
905 break;
906 }
907}
908
909static void
910mime_cache_init(void)
911{
912 Ecore_File_Monitor *mon;
913 Eina_List *datadirs, *l;
914 const char *s;
915 char buf[PATH_MAX];
916
917 mime_monitors = eina_hash_string_superfast_new(NULL);
918
919 mon = ecore_file_monitor_add("/etc/mime.types", mime_changes_cb, NULL);
920 if (mon) eina_hash_add(mime_monitors, "/etc/mime.types", mon);
921 mon = ecore_file_monitor_add("/usr/share/mime/globs", mime_changes_cb, NULL);
922 if (mon) eina_hash_add(mime_monitors, "/usr/share/mime/globs", mon);
923
924 datadirs = efreet_data_dirs_get();
925 EINA_LIST_FOREACH(datadirs, l, s)
926 {
927 snprintf(buf, sizeof(buf), "%s/mime/globs", s);
928 if (!eina_hash_find(mime_monitors, buf))
929 {
930 mon = ecore_file_monitor_add(buf, mime_changes_cb, NULL);
931 if (mon) eina_hash_add(mime_monitors, buf, mon);
932 }
933 }
934}
935
936static Eina_Bool
937mime_cache_monitor_del(const Eina_Hash *hash EINA_UNUSED,
938 const void *key EINA_UNUSED, void *value,
939 void *data EINA_UNUSED)
940{
941 Ecore_File_Monitor *mon = value;
942 ecore_file_monitor_del(mon);
943 return EINA_TRUE;
944}
945
946static void
947mime_cache_shutdown(void)
948{
949 if (mime_update_timer)
950 {
951 ecore_timer_del(mime_update_timer);
952 mime_update_timer = NULL;
953 }
954 if (mime_monitors)
955 {
956 eina_hash_foreach(mime_monitors, mime_cache_monitor_del, NULL);
957 eina_hash_free(mime_monitors);
958 mime_monitors = NULL;
959 }
960}
961
841Eina_Bool 962Eina_Bool
842cache_init(void) 963cache_init(void)
843{ 964{
@@ -875,6 +996,8 @@ cache_init(void)
875 efreet_cache_update = 0; 996 efreet_cache_update = 0;
876 if (!efreet_init()) goto error; 997 if (!efreet_init()) goto error;
877 subdir_cache_init(); 998 subdir_cache_init();
999 mime_cache_init();
1000 mime_update_launch();
878 read_lists(); 1001 read_lists();
879 /* TODO: Should check if system dirs has changed and handles extra_dirs */ 1002 /* TODO: Should check if system dirs has changed and handles extra_dirs */
880 desktop_system_dirs = efreet_default_dirs_get(efreet_data_home_get(), 1003 desktop_system_dirs = efreet_default_dirs_get(efreet_data_home_get(),
@@ -906,6 +1029,7 @@ cache_shutdown(void)
906 eina_prefix_free(pfx); 1029 eina_prefix_free(pfx);
907 pfx = NULL; 1030 pfx = NULL;
908 1031
1032 mime_cache_shutdown();
909 subdir_cache_shutdown(); 1033 subdir_cache_shutdown();
910 efreet_shutdown(); 1034 efreet_shutdown();
911 1035