Skip to content

Commit 5524840

Browse files
committed
Merge branch 'main' into release
2 parents 901af0c + ad5b556 commit 5524840

File tree

21 files changed

+580
-302
lines changed

21 files changed

+580
-302
lines changed

apps/infra-benchmarks/package.json

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
{
2+
"name": "infra-benchmarks",
3+
"private": true,
4+
"version": "0.0.0",
5+
"scripts": {
6+
"discriminated-union": "node --experimental-strip-types --expose-gc src/discriminated-union.ts"
7+
},
8+
"license": "MIT",
9+
"devDependencies": {
10+
"tinybench": "^3.1.0"
11+
},
12+
"packageManager": "[email protected]+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af"
13+
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
/*
2+
* This benchmark is used to find the fastest way to discriminate
3+
* types of objects that are hidden under a symbol. This information
4+
* will be used to best discriminate TypeGPU resources.
5+
*/
6+
7+
import { Bench } from 'tinybench';
8+
9+
const bench = new Bench({
10+
name: 'discriminated union',
11+
time: 100,
12+
async setup() {
13+
// biome-ignore lint/suspicious/noExplicitAny: making sure GC has no impact on the results
14+
(globalThis as any).gc();
15+
},
16+
});
17+
18+
const $internal = Symbol('Internal functionality');
19+
20+
// biome-ignore format: Long array
21+
const STRING_TAGS = ['aaa', 'bbb', 'ccc'] as const;
22+
const NUMBER_TAGS = [0, 1, 2] as const;
23+
const NUMBER_TAG_CATALOG = {
24+
aaa: 0,
25+
bbb: 1,
26+
ccc: 2,
27+
} as const;
28+
29+
const aaa = Symbol('aaa symbol');
30+
const bbb = Symbol('bbb symbol');
31+
const ccc = Symbol('ccc symbol');
32+
const SYMBOL_TAGS = [aaa, bbb, ccc] as const;
33+
34+
const NUMBER_OF_OBJS = 1000;
35+
36+
let stringTaggedObjs: {
37+
[$internal]: { type: (typeof STRING_TAGS)[number] };
38+
}[];
39+
let numberTaggedObjs: { [$internal]: { type: (typeof NUMBER_TAGS)[number] } }[];
40+
let symbolTaggedObjs: { [$internal]: { type: (typeof SYMBOL_TAGS)[number] } }[];
41+
let symbolKeyedObjs: { [K in (typeof SYMBOL_TAGS)[number]]: boolean }[];
42+
43+
bench
44+
.add(
45+
'string tags',
46+
() => {
47+
let count = 0;
48+
49+
for (const obj of stringTaggedObjs) {
50+
if (obj[$internal].type === 'aaa') {
51+
count += 2;
52+
} else if (obj[$internal].type === 'bbb') {
53+
count += 3;
54+
} else if (obj[$internal].type === 'ccc') {
55+
count += 4;
56+
}
57+
}
58+
},
59+
{
60+
beforeEach() {
61+
stringTaggedObjs = Array.from({ length: NUMBER_OF_OBJS }, () => ({
62+
[$internal]: {
63+
// biome-ignore lint/style/noNonNullAssertion: in range
64+
type: STRING_TAGS[Math.floor(Math.random() * STRING_TAGS.length)]!,
65+
},
66+
}));
67+
},
68+
},
69+
)
70+
.add(
71+
'number tags',
72+
async () => {
73+
let count = 0;
74+
75+
for (const obj of numberTaggedObjs) {
76+
if (obj[$internal].type === NUMBER_TAG_CATALOG.aaa) {
77+
count += 2;
78+
} else if (obj[$internal].type === NUMBER_TAG_CATALOG.bbb) {
79+
count += 3;
80+
} else if (obj[$internal].type === NUMBER_TAG_CATALOG.ccc) {
81+
count += 4;
82+
}
83+
}
84+
},
85+
{
86+
beforeEach() {
87+
numberTaggedObjs = Array.from({ length: NUMBER_OF_OBJS }, () => ({
88+
[$internal]: {
89+
// biome-ignore lint/style/noNonNullAssertion: in range
90+
type: NUMBER_TAGS[Math.floor(Math.random() * NUMBER_TAGS.length)]!,
91+
},
92+
}));
93+
},
94+
},
95+
)
96+
.add(
97+
'number tags (inlined catalog)',
98+
async () => {
99+
let count = 0;
100+
101+
for (const obj of numberTaggedObjs) {
102+
if (obj[$internal].type === 0) {
103+
count += 2;
104+
} else if (obj[$internal].type === 1) {
105+
count += 3;
106+
} else if (obj[$internal].type === 2) {
107+
count += 4;
108+
}
109+
}
110+
},
111+
{
112+
beforeEach() {
113+
numberTaggedObjs = Array.from({ length: NUMBER_OF_OBJS }, () => ({
114+
[$internal]: {
115+
// biome-ignore lint/style/noNonNullAssertion: in range
116+
type: NUMBER_TAGS[Math.floor(Math.random() * NUMBER_TAGS.length)]!,
117+
},
118+
}));
119+
},
120+
},
121+
)
122+
.add(
123+
'symbol tags',
124+
async () => {
125+
let count = 0;
126+
127+
for (const obj of symbolTaggedObjs) {
128+
if (obj[$internal].type === aaa) {
129+
count += 2;
130+
} else if (obj[$internal].type === bbb) {
131+
count += 3;
132+
} else if (obj[$internal].type === ccc) {
133+
count += 4;
134+
}
135+
}
136+
},
137+
{
138+
beforeEach() {
139+
symbolTaggedObjs = Array.from({ length: NUMBER_OF_OBJS }, () => ({
140+
[$internal]: {
141+
// biome-ignore lint/style/noNonNullAssertion: in range
142+
type: SYMBOL_TAGS[Math.floor(Math.random() * SYMBOL_TAGS.length)]!,
143+
},
144+
}));
145+
},
146+
},
147+
)
148+
.add(
149+
'symbol keys',
150+
async () => {
151+
let count = 0;
152+
153+
for (const obj of symbolKeyedObjs) {
154+
if (obj[aaa]) {
155+
count += 2;
156+
} else if (obj[bbb]) {
157+
count += 3;
158+
} else if (obj[ccc]) {
159+
count += 4;
160+
}
161+
}
162+
},
163+
{
164+
beforeEach() {
165+
symbolKeyedObjs = Array.from(
166+
{ length: NUMBER_OF_OBJS },
167+
() =>
168+
({
169+
// biome-ignore lint/style/noNonNullAssertion: in range
170+
[SYMBOL_TAGS[Math.floor(Math.random() * SYMBOL_TAGS.length)]!]:
171+
true,
172+
}) as { [K in (typeof SYMBOL_TAGS)[number]]: boolean },
173+
);
174+
},
175+
},
176+
);
177+
178+
await bench.run();
179+
180+
console.log(bench.name);
181+
console.table(bench.table());

apps/typegpu-docs/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
"motion": "^12.4.5",
4040
"react": "^19.0.0",
4141
"react-dom": "^19.0.0",
42-
"remeda": "^2.3.0",
42+
"remeda": "^2.21.2",
4343
"sharp": "^0.32.5",
4444
"starlight-blog": "^0.17.3",
4545
"starlight-typedoc": "^0.19.0",
@@ -51,7 +51,7 @@
5151
"typegpu": "workspace:*",
5252
"typescript": "catalog:",
5353
"unplugin-typegpu": "workspace:*",
54-
"wgpu-matrix": "^3.3.0"
54+
"wgpu-matrix": "^3.4.0"
5555
},
5656
"devDependencies": {
5757
"@types/babel__standalone": "^7.1.9",

apps/typegpu-docs/src/components/stackblitz/openInStackBlitz.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import StackBlitzSDK from '@stackblitz/sdk';
22
import { parse } from '@std/yaml';
33
import { type } from 'arktype';
4+
import typegpuoNoisePackageJson from '../../../../../packages/typegpu-noise/package.json';
45
import typegpuPackageJson from '../../../../../packages/typegpu/package.json';
56
import unpluginPackageJson from '../../../../../packages/unplugin-typegpu/package.json';
67
import pnpmWorkspace from '../../../../../pnpm-workspace.yaml?raw';
@@ -87,7 +88,8 @@ ${example.htmlCode}
8788
"unplugin-typegpu": "^${unpluginPackageJson.version}",
8889
"wgpu-matrix": "${typegpuDocsPackageJson.dependencies['wgpu-matrix']}",
8990
"@loaders.gl/core": "${typegpuDocsPackageJson.dependencies['@loaders.gl/core']}",
90-
"@loaders.gl/obj": "${typegpuDocsPackageJson.dependencies['@loaders.gl/obj']}"
91+
"@loaders.gl/obj": "${typegpuDocsPackageJson.dependencies['@loaders.gl/obj']}",
92+
"@typegpu/noise": "${typegpuoNoisePackageJson.version}"
9193
}
9294
}`,
9395
'vite.config.js': `\

apps/typegpu-docs/src/pages/benchmark/suites.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import type { TypeGPUDataModule, TypeGPUModule } from './modules';
55
import type { BenchParameterSet } from './parameter-set';
66
import { compiledWriteSuite } from './test-suites/compiled-write';
77
import { partialWriteSuite } from './test-suites/partial-write';
8+
import { vectorCreationSuite } from './test-suites/vector-creation';
89

910
export type TestIdentifier = `${string}_${string}`;
1011

@@ -39,6 +40,7 @@ export function createSuite<T extends { bench: Bench }>(
3940
export const unfilteredSuites: Record<string, Suite> = {
4041
'Partial write': partialWriteSuite,
4142
'Compiled write': compiledWriteSuite,
43+
'Vector creation': vectorCreationSuite,
4244
};
4345

4446
export function getFilteredSuites(selectedTests: TestIdentifier[]) {
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
import { Bench } from 'tinybench';
2+
import type { v2u, v3f, v4i } from 'typegpu/data';
3+
import { stringifyLocator } from '../parameter-set';
4+
import { createSuite } from '../suites';
5+
6+
export const vectorCreationSuite = createSuite(
7+
({ params, d }) => {
8+
const ctx = {
9+
bench: null as unknown as Bench,
10+
d,
11+
thousandVectors: [] as (v3f | v2u | v4i)[],
12+
tenThousandVectors: [] as (v3f | v2u | v4i)[],
13+
hundredThousandVectors: [] as (v3f | v2u | v4i)[],
14+
};
15+
16+
ctx.bench = new Bench({
17+
name: stringifyLocator('typegpu', params.typegpu),
18+
time: 1000,
19+
setup: () => {
20+
ctx.thousandVectors = Array.from({ length: 1000 });
21+
ctx.tenThousandVectors = Array.from({ length: 10000 });
22+
ctx.hundredThousandVectors = Array.from({ length: 100000 });
23+
},
24+
});
25+
26+
return ctx;
27+
},
28+
{
29+
'1k vectors': (getCtx) => async () => {
30+
const { thousandVectors: container, d } = getCtx();
31+
32+
for (let i = 0; i < container.length; i++) {
33+
container[i] = d.vec3f(1, 2, 3);
34+
}
35+
36+
for (let i = 0; i < container.length; i++) {
37+
container[i] = d.vec2u(1, 2);
38+
}
39+
40+
for (let i = 0; i < container.length; i++) {
41+
container[i] = d.vec4i(1, 2, 3, 4);
42+
}
43+
},
44+
45+
'10k vectors': (getCtx) => async () => {
46+
const { tenThousandVectors: container, d } = getCtx();
47+
48+
for (let i = 0; i < container.length; i++) {
49+
container[i] = d.vec3f(1, 2, 3);
50+
}
51+
52+
for (let i = 0; i < container.length; i++) {
53+
container[i] = d.vec2u(1, 2);
54+
}
55+
56+
for (let i = 0; i < container.length; i++) {
57+
container[i] = d.vec4i(1, 2, 3, 4);
58+
}
59+
},
60+
61+
'100k vectors': (getCtx) => async () => {
62+
const { hundredThousandVectors: container, d } = getCtx();
63+
64+
for (let i = 0; i < container.length; i++) {
65+
container[i] = d.vec3f(1, 2, 3);
66+
}
67+
68+
for (let i = 0; i < container.length; i++) {
69+
container[i] = d.vec2u(1, 2);
70+
}
71+
72+
for (let i = 0; i < container.length; i++) {
73+
container[i] = d.vec4i(1, 2, 3, 4);
74+
}
75+
},
76+
},
77+
);

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@
3737
"devDependencies": {
3838
"@biomejs/biome": "^1.9.4",
3939
"@webgpu/types": "catalog:",
40-
"@types/node": "^22.13.4",
40+
"@types/node": "^22.13.14",
4141
"dpdm": "^3.14.0",
42-
"pkg-pr-new": "^0.0.39",
42+
"pkg-pr-new": "^0.0.41",
4343
"tsup": "catalog:",
4444
"typescript": "catalog:",
4545
"vitest": "catalog:"

packages/tgpu-dev-cli/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
"consola": "^3.4.0",
1919
"execa": "^9.5.2",
2020
"is-unicode-supported": "^2.1.0",
21-
"remeda": "^2.3.0"
21+
"remeda": "^2.21.2"
2222
},
2323
"packageManager": "[email protected]+sha512.c753b6c3ad7afa13af388fa6d808035a008e30ea9993f58c6663e2bc5ff21679aa834db094987129aa4d488b86df57f7b634981b2f827cdcacc698cc0cfb88af"
2424
}

packages/tgpu-gen/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
"arg": "^5.0.2",
1515
"chokidar": "^4.0.1",
1616
"glob": "^11.0.0",
17-
"remeda": "^2.3.0",
17+
"remeda": "^2.21.2",
1818
"wgsl_reflect": "git://github.com/mhawryluk/wgsl_reflect.git#85994fdc8d8a3abbb4f79baf3891e54eed0c1c63"
1919
},
2020
"files": ["README.md", "LICENSE.md", "package.json", "**/*.mjs"],

0 commit comments

Comments
 (0)