⚡ Bolt: [performance improvement] Precalculate Derived Render Properties#39
⚡ Bolt: [performance improvement] Precalculate Derived Render Properties#39MrAlokTech wants to merge 1 commit intomainfrom
Conversation
Calculates `_searchStr`, `_isNew`, and `_formattedDate` when data is initialized in `prepareSearchIndex`, avoiding expensive string operations and object creation on every keypress during the `renderPDFs` loop. 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: |
1f77f34
|
| Status: | ✅ Deploy successful! |
| Preview URL: | https://df699bce.classnotes.pages.dev |
| Branch Preview URL: | https://bolt-precalculate-search-ind-ct5r.classnotes.pages.dev |
💡 What: Added a
prepareSearchIndexfunction that executes once after loading the PDF database. It appends pre-calculated derived properties (_searchStr,_isNew,_formattedDate) directly to the objects in the array. Refactored therenderPDFsfilter loop to use these pre-computed properties instead of computing them dynamically on every keystroke, and optimized the conditions with early returns.🎯 Why: The application features a live search capability that runs
renderPDFson every input keypress (debounced, but still frequent). Doing.toLowerCase()on multiple string fields, generating regexes, instantiating newDateobjects, and formatting them for every document dynamically during every render iteration is highly inefficient. Moving these calculations upstream to the initialization/caching phase prevents redundant computations.📊 Impact: Massively reduces string allocations and Date object instantions during live search and filter operations, resulting in lower CPU overhead and smoother keystrokes, particularly on slower mobile devices as the database scales.
🔬 Measurement:
Before: 1000 items would trigger 4000
.toLowerCase()string allocations, 1000Date()instantiations, and 1000 string concatenations on every single render cycle.After: 1000 items trigger 1000
.includes()string lookups on a single precomputed string per item. Date formatting and calculations happen 0 times per render cycle. Visual parity was verified.PR created automatically by Jules for task 13079143746385038976 started by @MrAlokTech