From b7af5c78026c026f871921f667f5277805845a52 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Thu, 2 Jul 2026 20:14:40 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Optimize=20handleSort=20in=20DomainsTable?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: yeboster <23556525+yeboster@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ src/routes/profile/DomainsTable.svelte | 12 +++++++----- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/.jules/bolt.md b/.jules/bolt.md index 91541609..8b00fc49 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. + +## 2024-11-20 - Sort Callback Allocation Overhead +**Learning:** Creating temporary arrays or using object destructuring inside an `Array.prototype.sort()` callback (e.g., `[a, b][condition ? 'slice' : 'reverse']()`) introduces heavy Garbage Collection overhead and slows down operations because it allocates new objects on every comparison. +**Action:** Refactor sorting logic to use straightforward scalar variable assignments and mathematical negations or multipliers for descending order. diff --git a/src/routes/profile/DomainsTable.svelte b/src/routes/profile/DomainsTable.svelte index c42bda5a..deabf94a 100644 --- a/src/routes/profile/DomainsTable.svelte +++ b/src/routes/profile/DomainsTable.svelte @@ -29,11 +29,13 @@ 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: Optimization - Use scalar assignments and a multiplier instead of array destructuring to avoid GC overhead + const aVal = a[sort]; + const bVal = b[sort]; + const modifier = sortDirection === 'ascending' ? 1 : -1; + if (typeof aVal === 'string' && typeof bVal === 'string') + return aVal.localeCompare(bVal) * modifier; + return (Number(aVal) - Number(bVal)) * modifier; }); domains = domains; }