Skip to content

⚡ Bolt: [performance improvement] Extract static objects in dashboard.js to reduce GC churn - #99

Closed
alvin000009238 wants to merge 1 commit into
devfrom
bolt-dashboard-gc-optimization-12629536715731939392
Closed

⚡ Bolt: [performance improvement] Extract static objects in dashboard.js to reduce GC churn#99
alvin000009238 wants to merge 1 commit into
devfrom
bolt-dashboard-gc-optimization-12629536715731939392

Conversation

@alvin000009238

Copy link
Copy Markdown
Owner

💡 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

…to reduce garbage collection overhead during render loops.

Co-authored-by: alvin000009238 <107313913+alvin000009238@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.

Copilot AI review requested due to automatic review settings March 31, 2026 10:01

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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_NAMES constant and reused it in shortenName().
  • Extracted score-level return objects to a module-scope SCORE_LEVELS constant and reused them in getScoreLevel().
  • 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.

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread frontend/dashboard.js
Comment on lines +271 to +278
const SHORT_NAMES = Object.freeze({
'英語文': '英文',
'公民與社會': '公民',
'選修化學-物質與能量': '化學',
'選修物理-力學一': '物理',
'選修化學': '化學',
'選修物理': '物理'
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

Comment thread frontend/dashboard.js
Comment on lines +325 to +331
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' })
});

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Similar to SHORT_NAMES, consider moving this constant to the top of the file. Centralizing static data at the top of the module is a common best practice in JavaScript to improve code discoverability and organization.

@alvin000009238
alvin000009238 deleted the bolt-dashboard-gc-optimization-12629536715731939392 branch May 13, 2026 12:47
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.

2 participants