From da42570966cbf1b46be973e5f1844bdc884c4297 Mon Sep 17 00:00:00 2001 From: "google-labs-jules[bot]" <161369871+google-labs-jules[bot]@users.noreply.github.com> Date: Wed, 7 Oct 2026 00:59:04 +0000 Subject: [PATCH] =?UTF-8?q?=E2=9A=A1=20Bolt:=20Optimize=20ISO=20date=20for?= =?UTF-8?q?matting=20and=20Nav=20pathname=20normalization?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: alehar9320 <5390430+alehar9320@users.noreply.github.com> --- .Jules/bolt.md | 4 ++++ src/components/Nav.astro | 16 ++++++++++------ src/utils/github-releases.ts | 5 ++++- 3 files changed, 18 insertions(+), 7 deletions(-) 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)); ---