Learning: During render loops, the code was repeatedly calling getFavorites(), which read from localStorage synchronously and JSON.parsed the data each time. This caused performance degradation in tight loops rendering the PDF list.
Action: Created favoritesCache global variable. getFavorites() will return favoritesCache if it is not null, otherwise read and parse from localStorage once. toggleFavorite() will update favoritesCache whenever a favorite is toggled. Next time I notice repetitive synchronous operations like localStorage.getItem combined with expensive conversions like JSON.parse inside render loops, I will consider using an in-memory cache to retrieve values instantly.