-
Notifications
You must be signed in to change notification settings - Fork 0
⚡ Bolt: [performance improvement] Extract static objects in dashboard.js to reduce GC churn #99
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
alvin000009238
wants to merge
1
commit into
dev
from
bolt-dashboard-gc-optimization-12629536715731939392
Closed
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -267,17 +267,19 @@ function getScoreClass(score) { | |
| return 'low'; | ||
| } | ||
|
|
||
| // 靜態科目縮寫對照表,提取至模組範圍以減少 GC | ||
| const SHORT_NAMES = Object.freeze({ | ||
| '英語文': '英文', | ||
| '公民與社會': '公民', | ||
| '選修化學-物質與能量': '化學', | ||
| '選修物理-力學一': '物理', | ||
| '選修化學': '化學', | ||
| '選修物理': '物理' | ||
| }); | ||
|
|
||
| // 縮短科目名稱 | ||
| export function shortenName(name) { | ||
| const shortNames = { | ||
| '英語文': '英文', | ||
| '公民與社會': '公民', | ||
| '選修化學-物質與能量': '化學', | ||
| '選修物理-力學一': '物理', | ||
| '選修化學': '化學', | ||
| '選修物理': '物理' | ||
| }; | ||
| return shortNames[name] || name; | ||
| return SHORT_NAMES[name] || name; | ||
| } | ||
|
|
||
| // 生成五標表格 | ||
|
|
@@ -319,13 +321,22 @@ function cleanSubjectName(name) { | |
| return name.replace(/<br\/>/g, ''); | ||
| } | ||
|
|
||
| // 靜態成績等級結果,提取至模組範圍以減少 render loop 中的物件配置與 GC | ||
| 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' }) | ||
| }); | ||
|
Comment on lines
+325
to
+331
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
|
|
||
| // 取得成績等級 | ||
| function getScoreLevel(score, std) { | ||
| if (score >= std["頂標"]) return { text: '頂標以上', class: 'excellent' }; | ||
| if (score >= std["前標"]) return { text: '前標以上', class: 'good' }; | ||
| if (score >= std["均標"]) return { text: '均標以上', class: 'average' }; | ||
| if (score >= std["後標"]) return { text: '後標以上', class: 'below' }; | ||
| return { text: '底標以下', class: 'poor' }; | ||
| if (score >= std["頂標"]) return SCORE_LEVELS.excellent; | ||
| if (score >= std["前標"]) return SCORE_LEVELS.good; | ||
| if (score >= std["均標"]) return SCORE_LEVELS.average; | ||
| if (score >= std["後標"]) return SCORE_LEVELS.below; | ||
| return SCORE_LEVELS.poor; | ||
| } | ||
|
|
||
| // 生成分佈圖 | ||
|
|
||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.