From 8ef8098969488c07064319b5205d292c3f2fbf2f Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Tue, 30 Jun 2026 20:04:15 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20[performance=20improvement]?= =?UTF-8?q?=20Eliminate=20GC=20overhead=20in=20domain=20sorting?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Refactored `handleSort` in `DomainsTable.svelte` to use scalar variable assignments instead of creating and slicing temporary arrays for every comparison. The previous implementation allocated a new array and called an array method on every single sort comparison, causing significant garbage collection (GC) overhead when sorting many domains. Reduces GC pauses and speeds up sorting operations from O(N log N) allocations to zero extra allocations per sort. Co-authored-by: yeboster <23556525+yeboster@users.noreply.github.com> --- .jules/bolt.md | 4 ++++ src/routes/profile/DomainsTable.svelte | 17 ++++++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) 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; }