Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .Jules/bolt.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`.
16 changes: 10 additions & 6 deletions src/components/Nav.astro
Original file line number Diff line number Diff line change
Expand Up @@ -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));
---

<nav aria-label="Main">
Expand Down
5 changes: 4 additions & 1 deletion src/utils/github-releases.ts
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,9 @@ export async function fetchGitHubReleases(

/**
* Formats an ISO date string into a YYYY-MM-DD format.
* Optimization (⚡ Bolt): Uses `.slice(0, 10)` instead of `.split('T')[0]` to extract YYYY-MM-DD
* directly from the ISO string without intermediate 2-element array allocations.
* Benchmark: Eliminates intermediate array creation per date formatting call.
* @param {string | null} dateString - The raw date string from the API.
* @returns {string} The formatted date, or 'Unknown date' if invalid.
*/
Expand All @@ -176,7 +179,7 @@ export function formatReleaseDate(dateString: string | null): string {
return 'Unknown date';
}

return date.toISOString().split('T')[0];
return date.toISOString().slice(0, 10);
}

/**
Expand Down
Loading