⚡ Bolt: [performance improvement] Pre-calculate search index and dates for faster render loops#31
Conversation
This commit improves frontend search and rendering performance by introducing `prepareSearchIndex`, which calculates lowercased search strings, parses `Date` objects, and pre-formats dates exactly once upon data load. It also restructures the `renderPDFs` filter loop to use early returns, saving CPU cycles on search rendering. Co-authored-by: MrAlokTech <107493955+MrAlokTech@users.noreply.github.com>
|
👋 Jules, reporting for duty! I'm here to lend a hand with this pull request. When you start a review, I'll add a 👀 emoji to each comment to let you know I've read it. I'll focus on feedback directed at me and will do my best to stay out of conversations between you and other bots or reviewers to keep the noise down. I'll push a commit with your requested changes shortly after. Please note there might be a delay between these steps, but rest assured I'm on the job! For more direct control, you can switch me to Reactive Mode. When this mode is on, I will only act on comments where you specifically mention me with New to Jules? Learn more at jules.google/docs. For security, I will only act on instructions from the user who triggered this task. |
Deploying classnotes with
|
| Latest commit: |
10acab6
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://aacca731.classnotes.pages.dev |
| Branch Preview URL: | https://bolt-precalculate-search-ind.classnotes.pages.dev |
💡 What: Introduced a
prepareSearchIndexfunction that pre-calculates the_searchStr(lowercased concatenation of title, description, category, and author),_formattedDate, and_isNewboolean for all PDF objects during theloadPDFDatabasephase. Updated therenderPDFsfilter callback to utilize early returns for exact matching (class, semester, category) before falling back to the cached search string matching. UpdatedcreatePDFCardto rely on the pre-calculated date attributes.🎯 Why: Previously, on every keystroke in the search bar (and every category/semester switch), the application was instantiating new
Dateobjects, calculating time differences, formatting strings, and executing four separate.toLowerCase().includes()operations per item in the loop. For large datasets, this caused noticeable jank and blocked the main thread.📊 Impact: Significantly reduces UI lag during search typing by moving date parsing and string lowercasing operations out of the O(n) render loop. The render filter is now highly optimized, dropping the number of string manipulations per keystroke per item from 4 to 0.
🔬 Measurement: Verify by typing rapidly in the search input on a large mock database; main thread blocking time should be noticeably reduced in DevTools performance profiling.
PR created automatically by Jules for task 787893586638098399 started by @MrAlokTech