From 0234f5cf7cdde85a13ea063d1c9aad86cae0c1ab Mon Sep 17 00:00:00 2001 From: seonghobae <8172694+seonghobae@users.noreply.github.com> Date: Thu, 13 Aug 2026 21:26:46 +0000 Subject: [PATCH] =?UTF-8?q?perf:=20String.padStart()=EB=A5=BC=20=EC=9D=B8?= =?UTF-8?q?=EB=9D=BC=EC=9D=B8=203=ED=95=AD=20=EC=97=B0=EC=82=B0=EC=9E=90?= =?UTF-8?q?=EB=A1=9C=20=EB=8C=80=EC=B2=B4=ED=95=98=EC=97=AC=20=EC=84=B1?= =?UTF-8?q?=EB=8A=A5=20=EC=B5=9C=EC=A0=81=ED=99=94?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .jules/bolt.md | 3 +++ app.js | 20 +++++++++++++++----- index.html | 2 ++ pr_desc.md | 21 ++++----------------- 4 files changed, 24 insertions(+), 22 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index b08b203a..1a50c452 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. +## 2026-08-13 - Replace String.padStart() with inline ternary concatenation +**Learning:** For performance optimizations in hot loops (e.g., date formatters), `String.padStart()` has unnecessary string allocations and JS-to-C++ overhead. +**Action:** Prefer using inline ternary string concatenation (e.g., `val < 10 ? '0' + val : '' + val`) instead of methods like `String.padStart()` to avoid unnecessary string allocations. diff --git a/app.js b/app.js index a04aae71..20f2369c 100644 --- a/app.js +++ b/app.js @@ -2682,22 +2682,32 @@ function clamp(value, min, max) { return Math.min(max, Math.max(min, value)); } +// β‘ Bolt: Replace String.padStart() with inline ternary concatenation in hot loops to avoid unnecessary string allocations and JS-to-C++ overhead function formatDateInput(date) { const year = date.getUTCFullYear(); - const month = String(date.getUTCMonth() + 1).padStart(2, '0'); - const day = String(date.getUTCDate()).padStart(2, '0'); + const m = date.getUTCMonth() + 1; + const month = m < 10 ? '0' + m : '' + m; + const d = date.getUTCDate(); + const day = d < 10 ? '0' + d : '' + d; return `${year}-${month}-${day}`; } function formatLocalDateInput(date) { const year = date.getFullYear(); - const month = String(date.getMonth() + 1).padStart(2, '0'); - const day = String(date.getDate()).padStart(2, '0'); + const m = date.getMonth() + 1; + const month = m < 10 ? '0' + m : '' + m; + const d = date.getDate(); + const day = d < 10 ? '0' + d : '' + d; return `${year}-${month}-${day}`; } function formatCompactDate(date) { - return `${date.getFullYear()}${String(date.getMonth() + 1).padStart(2, '0')}${String(date.getDate()).padStart(2, '0')}`; + const year = date.getFullYear(); + const m = date.getMonth() + 1; + const month = m < 10 ? '0' + m : '' + m; + const d = date.getDate(); + const day = d < 10 ? '0' + d : '' + d; + return `${year}${month}${day}`; } function formatPercent(value, digits) { diff --git a/index.html b/index.html index a7f4b49c..71af8121 100644 --- a/index.html +++ b/index.html @@ -7,6 +7,8 @@