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 @@