From 16f129c530cd32057195180180ea29824fc7045b Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 27 Aug 2026 21:33:40 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[=EC=84=B1=EB=8A=A5=20?= =?UTF-8?q?=EA=B0=9C=EC=84=A0]=20String.padStart=EB=A5=BC=20=EC=9D=B8?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=20=EC=82=BC=ED=95=AD=20=EC=97=B0=EC=82=B0?= =?UTF-8?q?=EC=9E=90=20=EB=AC=B8=EC=9E=90=EC=97=B4=20=EC=97=B0=EA=B2=B0?= =?UTF-8?q?=EB=A1=9C=20=EB=8C=80=EC=B2=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - `app.js`의 `formatDateInput`, `formatLocalDateInput`, `formatCompactDate` 함수에서 `String.padStart()` 사용 제거 - 핫 루프(Hot loop)에서 불필요한 문자열 할당 및 JS-to-C++ 오버헤드를 방지하기 위해 인라인 삼항 연산자 문자열 연결로 대체 - `index.html` 모듈 프리로드 최적화 복구 포함 --- .jules/bolt.md | 3 +++ app.js | 19 ++++++++++++------- index.html | 2 ++ 3 files changed, 17 insertions(+), 7 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index b08b203a..d45b3898 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -4,3 +4,6 @@ ## 2026-07-12 - Optimize renderTaskRow DOM allocations **Learning:** Caching unattached template nodes and instantiating them via `.cloneNode(false)` reduces DOM instantiation overhead in O(N) render loops significantly. **Action:** Apply this optimization to other hot-path rendering elements such as rows, cells, and stack containers. +## 2023-10-27 - [Avoid String.padStart in Hot Loops] +**Learning:** `String.padStart()` introduces unnecessary string allocations and JS-to-C++ context switching overhead in tight rendering loops like date formatters. +**Action:** Prefer using inline ternary string concatenation (e.g., `m < 10 ? '0' + m : m`) instead of `String.prototype.padStart()` for dynamic string padding in hot paths to avoid JS-to-C++ overhead and improve performance. diff --git a/app.js b/app.js index a04aae71..6a005703 100644 --- a/app.js +++ b/app.js @@ -2682,22 +2682,27 @@ function clamp(value, min, max) { return Math.min(max, Math.max(min, value)); } +// ⚡ Bolt: Inline ternary string concatenation avoids String.padStart() overhead in hot loops function formatDateInput(date) { const year = date.getUTCFullYear(); - const month = String(date.getUTCMonth() + 1).padStart(2, '0'); - const day = String(date.getUTCDate()).padStart(2, '0'); - return `${year}-${month}-${day}`; + const m = date.getUTCMonth() + 1; + const d = date.getUTCDate(); + return `${year}-${m < 10 ? '0' + m : m}-${d < 10 ? '0' + d : d}`; } +// ⚡ Bolt: Inline ternary string concatenation avoids String.padStart() overhead in hot loops function formatLocalDateInput(date) { const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); - return `${year}-${month}-${day}`; + const m = date.getMonth() + 1; + const d = date.getDate(); + return `${year}-${m < 10 ? '0' + m : m}-${d < 10 ? '0' + d : d}`; } +// ⚡ Bolt: Inline ternary string concatenation avoids String.padStart() overhead in hot loops function formatCompactDate(date) { - return `${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`; + const m = date.getMonth() + 1; + const d = date.getDate(); + return `${date.getFullYear()}${m < 10 ? '0' + m : m}${d < 10 ? '0' + d : d}`; } function formatPercent(value, digits) { diff --git a/index.html b/index.html index d24b2a88..879ad03b 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,8 @@