Skip to content

Commit e3ec444

Browse files
Merge pull request #261 from pmndrs/feat/span-publication-profile
perf(glyph): reuse unchanged span alignment for color updates
2 parents 15a3844 + 8bdd901 commit e3ec444

17 files changed

Lines changed: 633 additions & 67 deletions

‎.agents/docs/attestations/2026-10-09-glyph-4d68221c.md‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.agents/docs/attestations/2026-10-09-glyph-benchmarks-5a1b1122.md‎

Lines changed: 13 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.agents/docs/log/2026-10-08-reused-unchanged-span-alignment.md‎

Lines changed: 29 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.agents/docs/packages/benchmarks.md‎

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.agents/docs/packages/glyph.md‎

Lines changed: 4 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎.github/workflows/ci.yml‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ on:
1919
- measure
2020
- glyphs
2121
- publication
22+
- spans
2223
- batch
2324
- style
2425
- reflow
Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
import {
2+
borrowedChecksum,
3+
createLabels,
4+
disposeLabels,
5+
inspectDraws,
6+
inspectGlyphPaint,
7+
span,
8+
txt,
9+
} from './fixture.ts';
10+
11+
function formattedLabel(text: string) {
12+
return txt`${span({ color: '#ffffff', decoration: { underline: true } })`${text.slice(0, 5)}`}${text.slice(5)}`;
13+
}
14+
15+
function trailingSpanLabel(text: string, trailingColor: string): ReturnType<typeof formattedLabel> {
16+
const content = `${text} alpha beta gamma delta epsilon`;
17+
const literal = formattedLabel(content);
18+
const spanCount = 8;
19+
return {
20+
...literal,
21+
spans: Array.from({ length: spanCount }, (_, index) => ({
22+
start: Math.floor((content.length * index) / spanCount),
23+
end: Math.floor((content.length * (index + 1)) / spanCount),
24+
style: { color: index === spanCount - 1 ? trailingColor : '#ffffff' },
25+
})),
26+
};
27+
}
28+
29+
/** Exact trailing-span publication workload shared by Labs timing and attribution. */
30+
export function createTrailingSpanPublicationWorkload(count = 1_000) {
31+
const created = createLabels(count);
32+
const desired = ['#ff2f00', '#2f7fff'].map((trailingColor) =>
33+
created.labels.map((label) => ({ text: trailingSpanLabel(label.text, trailingColor) })),
34+
);
35+
let selected = 0;
36+
37+
const setNext = () => {
38+
selected = selected === 0 ? 1 : 0;
39+
const next = desired[selected]!;
40+
for (let index = 0; index < created.labels.length; index++) {
41+
created.labels[index]!.set(next[index]!);
42+
}
43+
};
44+
const commit = () => {
45+
created.scene.updateMatrixWorld(true);
46+
if (created.textGroup.error !== undefined) throw created.textGroup.error;
47+
return created.textGroup.textCount;
48+
};
49+
const update = () => {
50+
setNext();
51+
return commit();
52+
};
53+
const inspect = () => {
54+
const paint = inspectGlyphPaint(created.scene);
55+
return {
56+
checksum: borrowedChecksum(created.labels),
57+
draws: inspectDraws(created.scene),
58+
paint,
59+
paintMatchesSelected:
60+
selected === 0
61+
? paint.redDominant > 0 && paint.blueDominant === 0
62+
: paint.blueDominant > 0 && paint.redDominant === 0,
63+
textCount: created.textGroup.textCount,
64+
};
65+
};
66+
67+
return {
68+
commit,
69+
dispose: () => disposeLabels(created),
70+
inspect,
71+
setNext,
72+
update,
73+
};
74+
}
Lines changed: 14 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,7 @@
11
import { assert, bench, group } from '@pmndrs/labs';
22

3-
import { borrowedChecksum, createLabels, disposeLabels, inspectDraws, span, txt } from './fixture.ts';
4-
5-
function formattedLabel(text: string) {
6-
return txt`${span({ color: '#ffffff', decoration: { underline: true } })`${text.slice(0, 5)}`}${text.slice(5)}`;
7-
}
8-
9-
function trailingSpanLabel(text: string, trailingColor: string): ReturnType<typeof formattedLabel> {
10-
const content = `${text} alpha beta gamma delta epsilon`;
11-
const literal = formattedLabel(content);
12-
const spanCount = 8;
13-
return {
14-
...literal,
15-
spans: Array.from({ length: spanCount }, (_, index) => ({
16-
start: Math.floor((content.length * index) / spanCount),
17-
end: Math.floor((content.length * (index + 1)) / spanCount),
18-
style: { color: index === spanCount - 1 ? trailingColor : '#ffffff' },
19-
})),
20-
};
21-
}
3+
import { createTrailingSpanPublicationWorkload } from './adapter-publication-workload.ts';
4+
import { borrowedChecksum, createLabels, disposeLabels, inspectDraws } from './fixture.ts';
225

236
group('allocation-light adapter publication @publication', () => {
247
bench('normalize 1000 equivalent retained label updates @cached', function* () {
@@ -46,32 +29,17 @@ group('allocation-light adapter publication @publication', () => {
4629
});
4730

4831
bench('mutate one trailing span across 1000 formatted labels @spans', function* () {
49-
const count = 1_000;
50-
const created = createLabels(count);
51-
const desired = ['#ff2f00', '#2f7fff'].map((trailingColor) =>
52-
created.labels.map((label) => ({ text: trailingSpanLabel(label.text, trailingColor) })),
53-
);
54-
let selected = 0;
55-
56-
const update = () => {
57-
selected = selected === 0 ? 1 : 0;
58-
const next = desired[selected]!;
59-
for (let index = 0; index < created.labels.length; index++) {
60-
created.labels[index]!.set(next[index]!);
61-
}
62-
created.scene.updateMatrixWorld(true);
63-
if (created.textGroup.error !== undefined) throw created.textGroup.error;
64-
return created.textGroup.textCount;
65-
};
66-
update();
67-
const expectedChecksum = borrowedChecksum(created.labels);
68-
const expectedDraws = inspectDraws(created.textGroup);
69-
const textCount = yield update;
70-
assert.equal(textCount, count);
71-
assert.equal(borrowedChecksum(created.labels), expectedChecksum);
72-
assert.equal(inspectDraws(created.textGroup).glyphs, expectedDraws.glyphs);
73-
assert.equal(inspectDraws(created.textGroup).draws, expectedDraws.draws);
74-
75-
disposeLabels(created);
32+
const workload = createTrailingSpanPublicationWorkload();
33+
workload.update();
34+
const expected = workload.inspect();
35+
const textCount = yield workload.update;
36+
const actual = workload.inspect();
37+
assert.equal(textCount, 1_000);
38+
assert.equal(actual.checksum, expected.checksum);
39+
assert.equal(actual.draws.glyphs, expected.draws.glyphs);
40+
assert.equal(actual.draws.draws, expected.draws.draws);
41+
assert.equal(actual.paintMatchesSelected, true);
42+
43+
workload.dispose();
7644
});
7745
});

0 commit comments

Comments
 (0)