Skip to content

⚡ Bolt: Pre-calculate search index and format dates#46

Open
MrAlokTech wants to merge 1 commit intomainfrom
bolt-precalculate-search-dates-8429439962208687743
Open

⚡ Bolt: Pre-calculate search index and format dates#46
MrAlokTech wants to merge 1 commit intomainfrom
bolt-precalculate-search-dates-8429439962208687743

Conversation

@MrAlokTech
Copy link
Copy Markdown
Owner

💡 What:

  • Added a prepareSearchIndex function that calculates a _searchStr property (lowercased concatenation of title, description, category, author), _isNew boolean flag, and a _formattedDate string on the pdfDatabase objects.
  • Modified loadPDFDatabase to call prepareSearchIndex right after hydrating or fetching pdfDatabase, notably after saving to localStorage to avoid bloating the cache.
  • Refactored renderPDFs filtering logic to check the pre-calculated _searchStr and to use explicit early returns (if (!condition) return false;) rather than grouped boolean expressions.
  • Updated createPDFCard to consume the pre-calculated _isNew and _formattedDate properties instead of performing new Date() instantiations and formatting per card per render cycle.

🎯 Why:
The application suffered from unnecessary performance overhead during the renderPDFs search and filter loop. Instantiating Date objects repeatedly and recalculating strings (like .toLocaleDateString() and .toLowerCase()) inside a loop that handles large lists causes measurable UI slowdowns. Processing this derived data upstream reduces per-render computational complexity significantly.

📊 Impact:
This optimization significantly reduces CPU overhead during every keystroke of the search input and every tab/filter change. The time spent in the renderPDFs list rendering loop is drastically cut by avoiding redundant Date instantiations and lowercase string formatting calculations.

🔬 Measurement:
Run a local performance trace (e.g. Chrome DevTools -> Performance) while typing rapidly into the search input. The time taken per frame during renderPDFs execution will be visibly lower, eliminating potential jank and creating a smoother search experience. You can visually verify functionality via node -c script.js and starting the local index using python3 -m http.server 8000.


PR created automatically by Jules for task 8429439962208687743 started by @MrAlokTech

Co-authored-by: MrAlokTech <107493955+MrAlokTech@users.noreply.github.com>
@google-labs-jules
Copy link
Copy Markdown
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
Copy Markdown

Deploying classnotes with  Cloudflare Pages  Cloudflare Pages

Latest commit: e5cbb0c
Status: ✅  Deploy successful!
Preview URL: https://9afd9fdc.classnotes.pages.dev
Branch Preview URL: https://bolt-precalculate-search-dat.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