Skip to content

⚡ Bolt: [performance improvement] Precalculate Derived Render Properties#39

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

⚡ Bolt: [performance improvement] Precalculate Derived Render Properties#39
MrAlokTech wants to merge 1 commit intomainfrom
bolt-precalculate-search-index-13079143746385038976

Conversation

@MrAlokTech
Copy link
Owner

💡 What: Added a prepareSearchIndex function 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 the renderPDFs filter 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 renderPDFs on every input keypress (debounced, but still frequent). Doing .toLowerCase() on multiple string fields, generating regexes, instantiating new Date objects, 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, 1000 Date() 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

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>
@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: 1f77f34
Status: ✅  Deploy successful!
Preview URL: https://df699bce.classnotes.pages.dev
Branch Preview URL: https://bolt-precalculate-search-ind-ct5r.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