⚡ Bolt: Optimize renderPDFs filtering with pre-calculated search index and early returns#37
Conversation
…ly returns - Added `prepareSearchIndex` to pre-calculate a lowercased `_searchStr` for each PDF during initial load. - Refactored `pdfDatabase.filter` in `renderPDFs` to use explicit early returns, breaking out of conditions instantly upon failure. - Replaced multiple per-keystroke `toLowerCase` calls inside the filter loop with a single pre-calculated `_searchStr` substring check. - Added `.jules/bolt.md` to log performance learnings. 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: |
fb7c390
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://c0a0e605.classnotes.pages.dev |
| Branch Preview URL: | https://bolt-optimize-search-filter-6234.classnotes.pages.dev |
💡 What:
prepareSearchIndexutility that runs duringloadPDFDatabase(after caching) to attach a derived_searchStrproperty to every PDF object in memory.filtercallback insiderenderPDFsto use explicit early returns (if (!condition) return false;) instead of combined boolean logic.toLowerCase().includes()check with a simple substring check against the pre-calculated_searchStr.🎯 Why:
Previously, the filtering loop executed on every keystroke. It evaluated a single return statement containing multiple boolean conditions. This forced JavaScript to evaluate all conditions (even if the first one failed) and, worst of all, execute
.toLowerCase()on four different string properties for every item in the database, causing significant CPU overhead and potential main-thread blocking as the database grows.📊 Impact:
.toLowerCase()conversions occur during therenderPDFsloop, drastically reducing garbage collection pressure.classorsemestercheck are rejected instantly without executing the category or search string logic.🔬 Measurement:
renderPDFswill be noticeably shorter compared to themainbranch, as the callback now performs a simple array membership and cached string check.PR created automatically by Jules for task 3987269186906865892 started by @MrAlokTech