Skip to content

Latest commit

 

History

History
3 lines (3 loc) · 790 Bytes

File metadata and controls

3 lines (3 loc) · 790 Bytes

2024-03-20 - Cache favorites array to avoid redundant JSON parsing

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.