diff --git a/.Jules/bolt.md b/.Jules/bolt.md index f02512d4..07259ae9 100644 --- a/.Jules/bolt.md +++ b/.Jules/bolt.md @@ -41,3 +41,7 @@ Action: Updated `collectItems` in `src/utils/whats-new-glance.ts` to iterate ove 2026-09-08 - Zero-Allocation Reverse Array Scan for Chat Follow-up Prompts Learning: Dynamic shallow array copying and array reversal (`[...messages].reverse().find(...)`) on every UI update creates unnecessary temporary heap allocations and garbage collection overhead in client-side scripts. Replacing array copy/reverse with a reverse indexed `for` loop eliminates dynamic array allocations completely and stops scanning as soon as the first matching element is found. Action: Refactored `showFollowUps()` in `src/components/Chat.astro` to use an indexed reverse `for` loop. + +2026-09-09 - Zero-Allocation ISO Date Slicing & Hoisted Pathname Normalization +Learning: Using `.split('T')[0]` on ISO date strings allocates a temporary 2-element array per call, whereas `.slice(0, 10)` extracts `YYYY-MM-DD` directly without intermediate heap allocations. Additionally, normalizing active `Astro.url.pathname` inside loop functions (e.g. `isCurrentPage`) causes redundant regex and string replace operations across iterations during page renders; hoisting normalization outside the loop executes it once per component render. +Action: Updated `formatReleaseDate` in `src/utils/github-releases.ts` to use `.slice(0, 10)` and hoisted pathname normalization in `src/components/Nav.astro`. diff --git a/src/components/Nav.astro b/src/components/Nav.astro index 9fb82fed..3884bf84 100644 --- a/src/components/Nav.astro +++ b/src/components/Nav.astro @@ -42,13 +42,17 @@ const iconLinks: { }, ]; +/** + * Optimization (⚡ Bolt): Normalize active pathname once per component render rather than inside isCurrentPage loop. + * Benchmark: Saves 9 redundant string normalization and regex replace calls per page render across textLink iterations. + */ +let currentPath = Astro.url.pathname.replace(import.meta.env.BASE_URL, ''); +if (currentPath.at(0) !== '/') currentPath = '/' + currentPath; +if (currentPath.at(-1) !== '/') currentPath += '/'; + /** Test if a link is pointing to the current page. */ -const isCurrentPage = (href: string) => { - let pathname = Astro.url.pathname.replace(import.meta.env.BASE_URL, ''); - if (pathname.at(0) !== '/') pathname = '/' + pathname; - if (pathname.at(-1) !== '/') pathname += '/'; - return pathname === href || (href !== '/' && pathname.startsWith(href)); -}; +const isCurrentPage = (href: string) => + currentPath === href || (href !== '/' && currentPath.startsWith(href)); ---