⚡ Bolt: [performance improvement] Extract static objects in dashboard.js to reduce GC churn - #99
Conversation
…to reduce garbage collection overhead during render loops. Co-authored-by: alvin000009238 <107313913+alvin000009238@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. |
There was a problem hiding this comment.
Pull request overview
This PR optimizes the frontend dashboard rendering path by moving repeatedly-instantiated lookup objects to module scope, reducing per-render allocations and associated GC churn in frontend/dashboard.js.
Changes:
- Extracted the subject short-name lookup table to a module-scope
SHORT_NAMESconstant and reused it inshortenName(). - Extracted score-level return objects to a module-scope
SCORE_LEVELSconstant and reused them ingetScoreLevel(). - Applied
Object.freeze()to ensure these shared objects aren’t mutated at runtime.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
There was a problem hiding this comment.
Code Review
This pull request refactors frontend/dashboard.js by extracting SHORT_NAMES and SCORE_LEVELS into module-level frozen constants to optimize performance and reduce garbage collection. The reviewer suggests moving these static configuration objects to the top of the file to improve code organization and maintain consistency with existing constants.
| const SHORT_NAMES = Object.freeze({ | ||
| '英語文': '英文', | ||
| '公民與社會': '公民', | ||
| '選修化學-物質與能量': '化學', | ||
| '選修物理-力學一': '物理', | ||
| '選修化學': '化學', | ||
| '選修物理': '物理' | ||
| }); |
There was a problem hiding this comment.
While extracting these constants to the module scope is a great performance improvement, they are currently placed in the middle of the file. For better maintainability and consistency with other constants like SUBJECT_WEIGHTS (line 9), consider moving all static configuration objects to the top of the module.
| const SCORE_LEVELS = Object.freeze({ | ||
| excellent: Object.freeze({ text: '頂標以上', class: 'excellent' }), | ||
| good: Object.freeze({ text: '前標以上', class: 'good' }), | ||
| average: Object.freeze({ text: '均標以上', class: 'average' }), | ||
| below: Object.freeze({ text: '後標以上', class: 'below' }), | ||
| poor: Object.freeze({ text: '底標以下', class: 'poor' }) | ||
| }); |
💡 What: Extracted SHORT_NAMES and SCORE_LEVELS to module scope and used Object.freeze().
🎯 Why: These objects were being instantiated repeatedly inside render loops, causing unnecessary allocation and garbage collection (GC) overhead.
📊 Impact: Eliminates redundant GC overhead per row/card generated, reducing memory usage and render latency on large data sets.
🔬 Measurement: Verified with unit tests and production build.
PR created automatically by Jules for task 12629536715731939392 started by @alvin000009238