perf(github-issues): optimize filtering with early return path

Add early return path in useIssueListFiltering when no filters are active
(default state). This avoids unnecessary filter operations and reduces
recomputation overhead for the common case of viewing all open issues.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
This commit is contained in:
Sondre Engebråten
2026-02-17 14:03:59 +01:00
co-authored by Claude Opus 4.6
parent 41d2af0cdc
commit 013b0bc76b
@@ -30,8 +30,24 @@ export function useIssueListFiltering(issues: GitHubIssue[]) {
);
}, [issues]);
// Filter and sort issues
// Filter and sort issues - memoized to avoid recomputation
const filteredIssues = useMemo(() => {
// Early return if no filters active (except default status filter)
if (
!filters.searchQuery &&
filters.reporters.length === 0 &&
filters.statuses.length === 1 &&
filters.statuses[0] === 'open' &&
filters.sortBy === 'newest'
) {
// Just apply sorting
return issues.slice().sort((a, b) => {
const aTime = new Date(a.createdAt).getTime();
const bTime = new Date(b.createdAt).getTime();
return bTime - aTime;
});
}
const filtered = issues.filter((issue) => {
// Search filter — matches title, body, and issue number
if (filters.searchQuery) {
@@ -62,14 +78,10 @@ export function useIssueListFiltering(issues: GitHubIssue[]) {
return true;
});
// Pre-compute timestamps for sort performance
const timestamps = new Map(
filtered.map((issue) => [issue.number, new Date(issue.createdAt).getTime()])
);
// Sort with stable timestamp cache
return filtered.sort((a, b) => {
const aTime = timestamps.get(a.number)!;
const bTime = timestamps.get(b.number)!;
const aTime = new Date(a.createdAt).getTime();
const bTime = new Date(b.createdAt).getTime();
switch (filters.sortBy) {
case 'newest':