You are effectively using the filesystem as a database and trusting that the directory-entry correctly reflects the file size. Benchmarking will probably reveal that your approach is slower. Read the preferences from the database once and keep them in memory. Don't retrieve them in a loop.