Add benchmark for sidebar sublist processing (#4216)

This commit is contained in:
Chris Swithinbank
2026-09-24 13:23:24 +02:00
committed by GitHub
parent f5f7768598
commit fafea30324
@@ -1,8 +1,10 @@
import { klona } from 'klona';
import { bench, describe, vi } from 'vitest';
import { getRouteDataTestContext } from '../__tests__/test-utils';
import { generateRouteData } from '../src/utils/routing/data';
import { getRouteBySlugParam } from '../src/utils/routing';
import { getSidebar } from '../src/utils/navigation';
import { flattenSidebar, getSidebar } from '../src/utils/navigation';
import type { SidebarEntry } from '../src/utils/routing/types';
const docs = vi.hoisted(() => {
const docs: [string, { title: string }][] = [];
@@ -48,3 +50,17 @@ describe('routing', () => {
getSidebar(context.url.pathname, route.locale);
});
});
/** Recursive function that simulates the heavier logic in `<SidebarSublist>` rendering. */
function mockSidebarRender(sublist: SidebarEntry[]) {
for (const entry of sublist) {
if (entry.type !== 'link') {
flattenSidebar(entry.entries).some((i) => i.isCurrent);
mockSidebarRender(entry.entries);
}
}
}
bench('sidebar current groups', () => {
mockSidebarRender(klona(getSidebar(context.url.pathname, route.locale)));
});