Skip to content

⚡ Bolt: [performance improvement] Pre-calculate search index and dates for faster render loops#31

Open
MrAlokTech wants to merge 1 commit intomainfrom
bolt/precalculate-search-index-787893586638098399
Open

⚡ Bolt: [performance improvement] Pre-calculate search index and dates for faster render loops#31
MrAlokTech wants to merge 1 commit intomainfrom
bolt/precalculate-search-index-787893586638098399

Conversation

@MrAlokTech
Copy link
Owner

💡 What: Introduced a prepareSearchIndex function that pre-calculates the _searchStr (lowercased concatenation of title, description, category, and author), _formattedDate, and _isNew boolean for all PDF objects during the loadPDFDatabase phase. Updated the renderPDFs filter callback to utilize early returns for exact matching (class, semester, category) before falling back to the cached search string matching. Updated createPDFCard to 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 Date objects, 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

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>
@google-labs-jules
Copy link
Contributor

👋 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 @jules. You can find this option in the Pull Request section of your global Jules UI settings. You can always switch back!

New to Jules? Learn more at jules.google/docs.


For security, I will only act on instructions from the user who triggered this task.

@cloudflare-workers-and-pages
Copy link

Deploying classnotes with  Cloudflare Pages  Cloudflare Pages

Latest commit: 10acab6
Status: ✅  Deploy successful!
Preview URL: https://aacca731.classnotes.pages.dev
Branch Preview URL: https://bolt-precalculate-search-ind.classnotes.pages.dev

View logs

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant