Rockbox open source high quality audio player as a Music Player Daemon
mpris rockbox mpd libadwaita audio rust zig deno
2
fork

Configure Feed

Select the types of activity you want to include in your feed.

playlist: reduce memory usage for loading playlists

There's probably little benefit to using core_alloc_maximum() for
loading playlists since they are parsed incrementally. I/O speed
does not increase with increased read sizes beyond a certain point.
Read by 32 KiB chunks since that is what the buffering thread does.
Fall back to core_alloc_maximum() if a small allocation fails so
that buflib will try harder to free up space.

Change-Id: I08b94317d12b98af09ef2bd84aa1195c4c51d1b1

+31 -8
+31 -8
apps/playlist.c
··· 124 124 //NOTEF 125 125 #endif 126 126 127 - 128 - 127 + /* default load buffer size (should be at least 1 KiB) */ 128 + #define PLAYLIST_LOAD_BUFLEN (32*1024) 129 129 130 130 131 131 #define PLAYLIST_CONTROL_FILE_VERSION 2 ··· 1999 1999 } 2000 2000 2001 2001 /* 2002 + * Allocate a temporary buffer for loading playlists 2003 + */ 2004 + static int alloc_tempbuf(size_t* buflen) 2005 + { 2006 + /* request a reasonable size first */ 2007 + int handle = core_alloc_ex(NULL, PLAYLIST_LOAD_BUFLEN, &buflib_ops_locked); 2008 + if (handle > 0) 2009 + { 2010 + *buflen = PLAYLIST_LOAD_BUFLEN; 2011 + return handle; 2012 + } 2013 + 2014 + /* otherwise, try being unreasonable */ 2015 + return core_alloc_maximum(NULL, buflen, &buflib_ops_locked); 2016 + } 2017 + 2018 + /* 2002 2019 * Need no movement protection since all 3 allocations are not passed to 2003 2020 * other functions which can yield(). 2004 2021 */ ··· 2097 2114 2098 2115 if (file) 2099 2116 { 2100 - int handle; 2101 2117 size_t buflen; 2102 - /* use mp3 buffer for maximum load speed */ 2103 - handle = core_alloc_maximum("temp", &buflen, &buflib_ops_locked); 2118 + int handle = alloc_tempbuf(&buflen); 2104 2119 if (handle > 0) 2105 2120 { 2121 + /* align for faster load times */ 2122 + void* buf = core_get_data(handle); 2123 + STORAGE_ALIGN_BUFFER(buf, buflen); 2124 + buflen = ALIGN_DOWN(buflen, 512); /* to avoid partial sector I/O */ 2125 + 2106 2126 /* load the playlist file */ 2107 - add_indices_to_playlist(playlist, core_get_data(handle), buflen); 2127 + add_indices_to_playlist(playlist, buf, buflen); 2108 2128 core_free(handle); 2109 2129 } 2110 2130 else ··· 2145 2165 dircache_wait(); /* we need the dircache to use the files in the playlist */ 2146 2166 #endif 2147 2167 2148 - /* use mp3 buffer for maximum load speed */ 2149 - handle = core_alloc_maximum("temp", &buflen, &buflib_ops_locked); 2168 + handle = alloc_tempbuf(&buflen); 2150 2169 if (handle < 0) 2151 2170 { 2152 2171 splashf(HZ * 2, "%s(): OOM", __func__); 2153 2172 return -1; 2154 2173 } 2174 + 2175 + /* align buffer for faster load times */ 2155 2176 buffer = core_get_data(handle); 2177 + STORAGE_ALIGN_BUFFER(buffer, buflen); 2178 + buflen = ALIGN_DOWN(buflen, 512); /* to avoid partial sector I/O */ 2156 2179 2157 2180 playlist_shutdown(); /* flush any cached control commands to disk */ 2158 2181 empty_playlist(playlist, true);