diff --git a/.jules/bolt.md b/.jules/bolt.md index b08b203a..46db241f 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-07-12 - Avoid String.padStart() overhead in date formatters +**Learning:** Using `String().padStart()` inside hot loops (like O(N) rendering functions where date formatting is frequently used) incurs unnecessary string allocations and JS-to-C++ overhead. +**Action:** Prefer using inline ternary string concatenation (`val < 10 ? '0' + val : val`) for simple zero-padding logic to optimize performance. diff --git a/app.js b/app.js index a04aae71..450ec223 100644 --- a/app.js +++ b/app.js @@ -2684,20 +2684,31 @@ function clamp(value, min, max) { function formatDateInput(date) { const year = date.getUTCFullYear(); - const month = String(date.getUTCMonth() + 1).padStart(2, '0'); - const day = String(date.getUTCDate()).padStart(2, '0'); + // ⚡ Optimization: Use inline ternary instead of String.padStart() to avoid string allocations and JS-to-C++ overhead + const m = date.getUTCMonth() + 1; + const d = date.getUTCDate(); + const month = m < 10 ? '0' + m : m; + 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'); + // ⚡ Optimization: Use inline ternary instead of String.padStart() to avoid string allocations and JS-to-C++ overhead + const m = date.getMonth() + 1; + const d = date.getDate(); + const month = m < 10 ? '0' + m : m; + 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')}`; + // ⚡ Optimization: Use inline ternary instead of String.padStart() to avoid string allocations and JS-to-C++ overhead + const m = date.getMonth() + 1; + const d = date.getDate(); + const month = m < 10 ? '0' + m : m; + const day = d < 10 ? '0' + d : d; + return `${date.getFullYear()}${month}${day}`; } function formatPercent(value, digits) { diff --git a/index.html b/index.html index a7f4b49c..cda50f78 100644 --- a/index.html +++ b/index.html @@ -6,6 +6,8 @@