diff --git a/.jules/bolt.md b/.jules/bolt.md index 91541609..9ced92dc 100644 --- a/.jules/bolt.md +++ b/.jules/bolt.md @@ -9,3 +9,7 @@ **Learning:** Using `on:keyup` for search input debouncing triggers unnecessary API calls on navigation keys (arrows, home, end) and misses changes from paste/cut. Svelte's reactive statements `$: debounce(value)` provide a robust, declarative way to trigger debouncing only when the value actually changes. **Action:** Replace `on:keyup` handlers with reactive statements for input debouncing to improve performance and correctness. + +## 2025-02-24 - Sorting Garbage Collection Overhead +**Learning:** Creating temporary arrays inside an `Array.prototype.sort()` callback (e.g., `[a, b][condition ? 'slice' : 'reverse']()`) generates massive garbage collection overhead since the array is re-allocated for every single comparison. +**Action:** Refactor sorting logic to use straightforward scalar variable assignments and mathematical negations for descending order. diff --git a/src/routes/profile/DomainsTable.svelte b/src/routes/profile/DomainsTable.svelte index c42bda5a..69ee1e7f 100644 --- a/src/routes/profile/DomainsTable.svelte +++ b/src/routes/profile/DomainsTable.svelte @@ -29,11 +29,18 @@ function handleSort() { domains.sort((a, b) => { - const [aVal, bVal] = [a[sort], b[sort]][ - sortDirection === 'ascending' ? 'slice' : 'reverse' - ](); - if (typeof aVal === 'string' && typeof bVal === 'string') return aVal.localeCompare(bVal); - return Number(aVal) - Number(bVal); + // ⚡ Bolt: Use scalar assignment to avoid temporary array allocation (GC overhead) in every comparison + const aVal = a[sort]; + const bVal = b[sort]; + let comparison = 0; + + if (typeof aVal === 'string' && typeof bVal === 'string') { + comparison = aVal.localeCompare(bVal); + } else { + comparison = Number(aVal) - Number(bVal); + } + + return sortDirection === 'ascending' ? comparison : -comparison; }); domains = domains; }