⚡ Bolt: Remove JSON serialization overhead & memoize lookups#12
⚡ Bolt: Remove JSON serialization overhead & memoize lookups#12mentalblank wants to merge 1 commit into
Conversation
- Switch `collectionROMList` storage in IndexedDB from JSON string to raw Object, removing ~90ms blocking time on large data loads. - Add lazy migration logic to handle legacy stringified data. - Memoize `gameHashesMap` in `injectGames` to prevent redundant hash map construction on every DOM mutation. Co-authored-by: mentalblank <12580160+mentalblank@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. |
PR Compliance Guide 🔍Below is a summary of compliance checks for this PR:
Compliance status legend🟢 - Fully Compliant🟡 - Partial Compliant 🔴 - Not Compliant ⚪ - Requires Further Human Verification 🏷️ - Compliance label |
|||||||||||||||||||||||||
PR Code Suggestions ✨Explore these optional code suggestions:
|
|||||||||||||
User description
💡 What:
IndexedDBstorage forcollectionROMListto store the raw JavaScript object instead of a JSON string.gameHashesMapgeneration ininjectGames, reusing the map if the game ID and data reference haven't changed.🎯 Why:
hashlinks.jsonis ~6.4MB.JSON.parseandJSON.stringifyon this data take significant time (~90ms blocking the main thread) every time data is loaded or saved. Storing as an object leverages IndexedDB's structured cloning, which is generally more efficient and doesn't block the script execution flow as heavily (or at least avoids the explicit double-handling).handleRAis triggered by aMutationObserveron the body. While it has some safeguards, it can still triggerinjectGamesfrequently. Rebuilding thegameHashesMap(iterating over game data) on every call is wasteful.📊 Impact:
🔬 Measurement:
verify_changes.js.PR created automatically by Jules for task 13872188841744034412 started by @mentalblank
PR Type
Enhancement
Description
Remove JSON serialization overhead by storing raw objects in IndexedDB instead of stringified JSON
Implement memoization for gameHashesMap to prevent redundant hash map reconstruction on DOM mutations
Add migration logic to handle legacy stringified data and upgrade to object storage
Reduce blocking time (~90ms) on large data loads and CPU usage during frequent DOM updates
Diagram Walkthrough
File Walkthrough
TamperMonkeyRetroachievements.js
Optimize storage and memoize hash map generationTamperMonkeyRetroachievements.js
lastGameData,lastGameId,lastGameHashesMap) to cache hash map generationinjectGamesfunction to reuse cached hash map when game dataand ID haven't changed
fetchDatafunction to store raw objects instead of JSONstrings in IndexedDB
upgrade storage format