Skip to content
Open
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
37 changes: 12 additions & 25 deletions bun.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions js-packages/profiler-layout/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
"@tailwindcss/vite": "^4.1.17",
"@vitest/browser-playwright": "^4.1.8",
"feldera-theme": "workspace:*",
"jsdom": "^29.1.1",

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: jsdom is added to devDependencies, but vitest.config.ts already runs in real Chromium via @vitest/browser-playwright and this test only exercises pure logic. Is jsdom actually required by something, or can this dep be dropped?

"monaco-editor": "0.55.1",
"playwright": "1.58.2",
"profiler-lib": "workspace:*",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import { describe, expect, it } from 'vitest'
import type { NodeAttributes, TooltipRow } from 'profiler-lib'
import { buildBlocks } from './dispatch.js'

function row(metric: string): TooltipRow {
return { metric, isCurrentMetric: false, cells: [] }
}

function makeAttrs(metrics: string[]): NodeAttributes {
return {
title: 'n op',

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot guess what this is

columns: [],
rows: metrics.map(row),
attributes: new Map()
}
}

describe('buildBlocks', () => {
it('orders metrics lexicographically inside each block (case-insensitive)', () => {
// Metric IDs span categories; the order is intentionally scrambled to confirm the sort.
const attrs = makeAttrs([
'zeta_seconds',
'Alpha_count',
'gamma_size',
'alpha_total'
])
const blocks = buildBlocks(attrs, /* showAdvanced */ true)
// All metrics fall into the same "Other" bucket (no descriptions registered),
// so we expect a single block whose entries are alphabetised by label.
const all = blocks.flatMap((b) => b.entries.map((e) => e.label))
const sorted = [...all].sort((a, b) =>
new Intl.Collator(undefined, { sensitivity: 'base', numeric: true }).compare(a, b)
)
expect(all).toEqual(sorted)
// Sanity: the original input was not already sorted.
expect(attrs.rows.map((r) => r.metric)).not.toEqual(sorted)
})

it('uses natural-number ordering, not raw codepoint order', () => {
// Labels like "slot 2" / "slot 10" share a numeric suffix; a plain ASCII sort would put
// "slot 10" before "slot 2".
const attrs = makeAttrs(['slot_10_loose', 'slot_2_loose', 'slot_1_loose'])
const blocks = buildBlocks(attrs, true)
const labels = blocks.flatMap((b) => b.entries.map((e) => e.label))
expect(labels).toEqual(['Slot 1 loose', 'Slot 2 loose', 'Slot 10 loose'])
})
})
11 changes: 11 additions & 0 deletions js-packages/profiler-layout/src/lib/components/metrics/dispatch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,17 @@ export function buildBlocks(attrs: NodeAttributes, showAdvanced: boolean): Rende
})
}

// Sort metrics inside each block by their displayed label so users can scan a long block
// without re-reading the whole thing. Locale-aware compare with `numeric: true`
// keeps numbered labels like "slot 2 ..." / "slot 10 ..." in their natural sequence.
const collator = new Intl.Collator(undefined, { sensitivity: 'base', numeric: true })
for (const entries of byCategory.values()) {
entries.sort(
(a, b) =>
collator.compare(a.label, b.label) || collator.compare(a.row.metric, b.row.metric)
)
}

const out: RenderableBlock[] = []
for (const [category, entries] of byCategory) {
out.push({ id: `category-${slugify(category)}`, title: category, entries })
Expand Down
Loading