Skip to content

Commit eabdc2c

Browse files
committed
wip: setup benchmark test
1 parent 44feae4 commit eabdc2c

File tree

10 files changed

+109
-63
lines changed

10 files changed

+109
-63
lines changed

packages/angular-table/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
"test:build": "publint --strict",
4747
"test:eslint": "eslint ./src",
4848
"test:lib": "vitest",
49+
"test:benchmark": "vitest bench",
4950
"test:lib:dev": "vitest --watch",
5051
"test:types": "tsc && vitest --typecheck"
5152
},

packages/angular-table/src/angularReactivityFeature.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ export function constructAngularReactivityFeature<
7575
equal: () => false,
7676
})
7777

78+
if (table.options.reactivity?.table === false) {
79+
return
80+
}
7881
markReactive(table)
7982
setReactiveProps(table.get, table, {
8083
skipProperty: skipBaseProperties,

packages/angular-table/src/flex-render.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,6 @@ export class FlexRenderDirective<
158158
this.#tableChangeEffect?.destroy()
159159
this.#tableChangeEffect = null
160160
let firstCheck = !!(this.renderFlags & FlexRenderFlags.ViewFirstRender)
161-
console.log(this.table)
162161
if (
163162
this.table &&
164163
this.notifier === 'tableChange' &&

packages/angular-table/src/reactivityUtils.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@ export function defineLazyComputedProperty<T extends object>(
4343
configurable: true,
4444
enumerable: true,
4545
})
46-
4746
return computedValue
4847
},
4948
})

packages/angular-table/tests/benchmark.test.ts

Lines changed: 0 additions & 53 deletions
This file was deleted.
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { setTimeout } from 'node:timers/promises'
2+
import { bench, describe } from 'vitest'
3+
import { benchCases, columns, createTestTable, dataMap } from './setup'
4+
5+
const nIteration = 5
6+
7+
for (const benchCase of benchCases) {
8+
describe(`injectTable (${benchCase.size} elements)`, () => {
9+
const data = dataMap[benchCase.size]!
10+
11+
bench(
12+
`${benchCase.size} elements - No reactivity`,
13+
async () => {
14+
const table = createTestTable(false, data, columns)
15+
await setTimeout(0)
16+
table.getRowModel()
17+
},
18+
{
19+
iterations: nIteration,
20+
},
21+
)
22+
23+
bench(
24+
`${benchCase.size} Enabled reactivity`,
25+
async () => {
26+
const table = createTestTable(true, data, columns)
27+
await setTimeout(0)
28+
table.getRowModel()
29+
},
30+
{
31+
iterations: nIteration,
32+
},
33+
)
34+
})
35+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import { injectTable, stockFeatures } from '../../src'
2+
import type { ColumnDef } from '../../src'
3+
4+
export function createData(size: number) {
5+
return Array.from({ length: size }, (_, index) => ({
6+
id: index,
7+
title: `title-${index}`,
8+
name: `name-${index}`,
9+
}))
10+
}
11+
12+
export const columns: Array<ColumnDef<typeof stockFeatures, any>> = [
13+
{ id: 'col1' },
14+
{ id: 'col2' },
15+
{ id: 'col3' },
16+
{ id: 'col4' },
17+
{ id: 'col5' },
18+
{ id: 'col6' },
19+
{ id: 'col7' },
20+
]
21+
22+
export function createTestTable(
23+
enableGranularReactivity: boolean,
24+
data: Array<any>,
25+
columns: Array<any>,
26+
) {
27+
return injectTable(() => ({
28+
_features: stockFeatures,
29+
columns: columns,
30+
data,
31+
reactivity: {
32+
table: enableGranularReactivity,
33+
row: enableGranularReactivity,
34+
column: enableGranularReactivity,
35+
cell: enableGranularReactivity,
36+
header: enableGranularReactivity,
37+
},
38+
}))
39+
}
40+
41+
export const benchCases = [
42+
{ size: 100, max: 5, threshold: 10 },
43+
{ size: 1000, max: 25, threshold: 50 },
44+
{ size: 2000, max: 50, threshold: 100 },
45+
{ size: 5000, max: 100, threshold: 500 },
46+
{ size: 10_000, max: 200, threshold: 1000 },
47+
{ size: 25_000, max: 500, threshold: 1000 },
48+
{ size: 50_000, max: 1500, threshold: 1000 },
49+
{ size: 100_000, max: 2000, threshold: 1500 },
50+
]
51+
52+
console.log('Seeding data...')
53+
54+
export const dataMap = {} as Record<number, Array<any>>
55+
56+
for (const benchCase of benchCases) {
57+
dataMap[benchCase.size] = createData(benchCase.size)
58+
}
59+
60+
console.log('Seed data completed')

packages/angular-table/tests/flex-render-component.test-d.ts renamed to packages/angular-table/tests/flex-render/flex-render-component.test-d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { input } from '@angular/core'
22
import { test } from 'vitest'
3-
import { flexRenderComponent } from '../src'
3+
import { flexRenderComponent } from '../../src'
44

55
test('Infer component inputs', () => {
66
class Test {

packages/angular-table/tests/flex-render-table.test.ts renamed to packages/angular-table/tests/flex-render/flex-render-table.test.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ import {
1919
flexRenderComponent,
2020
injectFlexRenderContext,
2121
injectTable,
22-
} from '../src'
23-
import type { FlexRenderContent } from '../src'
22+
} from '../../src'
23+
import type { FlexRenderContent } from '../../src'
2424
import type {
2525
CellContext,
2626
ExpandedState,

packages/angular-table/tests/flex-render.test.ts renamed to packages/angular-table/tests/flex-render/flex-render.unit.test.ts

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,15 @@
1-
import { Component, input, type TemplateRef, ViewChild } from '@angular/core'
2-
import { type ComponentFixture, TestBed } from '@angular/core/testing'
1+
import { Component, ViewChild, input } from '@angular/core'
2+
import { TestBed } from '@angular/core/testing'
33
import { createColumnHelper } from '@tanstack/table-core'
44
import { describe, expect, test } from 'vitest'
55
import {
66
FlexRenderDirective,
77
injectFlexRenderContext,
8-
} from '../src/flex-render'
9-
import { setFixtureSignalInput, setFixtureSignalInputs } from './test-utils'
10-
import { flexRenderComponent } from '../src/flex-render/flex-render-component'
8+
} from '../../src/flex-render'
9+
import { setFixtureSignalInput, setFixtureSignalInputs } from '../test-utils'
10+
import { flexRenderComponent } from '../../src/flex-render/flex-render-component'
11+
import type { TemplateRef } from '@angular/core'
12+
import type { ComponentFixture } from '@angular/core/testing'
1113

1214
interface Data {
1315
id: string

0 commit comments

Comments
 (0)