فینورا پرو - سامانه جامع حسابداری و صدور فاکتور
feat(A08): collect repeatable synthetic 10k/50k performance baseline
* feat(A08): add deterministic 10k-product 50k-invoice IndexedDB performance baseline * test(A08): verify deterministic synthetic baseline fixture * ci(A08): measure and upload 10k/50k synthetic performance report
davoodmehraban89 committed
Oct 14, 2026 at 23:28 UTC
72b4a0c109101533d94278481770520599f26aa2
3 files changed
+148
.github/workflows/a08-benchmark.yml
new
+34
@@ -0,0 +1,34 @@
1
+name: A08 synthetic performance baseline
2
+on:
3
+ pull_request:
4
+ paths:
5
+ - 'scripts/a08-benchmark.mjs'
6
+ - 'tests/a08-benchmark-fixtures.test.mjs'
7
+ - '.github/workflows/a08-benchmark.yml'
8
+ workflow_dispatch:
9
+permissions:
10
+ contents: read
11
+jobs:
12
+ synthetic-baseline:
13
+ runs-on: ubuntu-latest
14
+ timeout-minutes: 25
15
+ steps:
16
+ - uses: actions/checkout@v4
17
+ with:
18
+ persist-credentials: false
19
+ - uses: actions/setup-node@v4
20
+ with:
21
+ node-version: '22'
22
+ cache: npm
23
+ - run: npm ci
24
+ - name: Verify deterministic fixture
25
+ run: node --test tests/a08-benchmark-fixtures.test.mjs
26
+ - name: Measure 10k products and 50k invoices
27
+ run: node --expose-gc scripts/a08-benchmark.mjs
28
+ - name: Upload measured report
29
+ uses: actions/upload-artifact@v4
30
+ with:
31
+ name: a08-synthetic-baseline
32
+ path: a08-benchmark-results.json
33
+ retention-days: 30
34
+ if-no-files-found: error
scripts/a08-benchmark.mjs
new
+96
@@ -0,0 +1,96 @@
1
+import 'fake-indexeddb/auto';
2
+import { writeFileSync } from 'node:fs';
3
+import { pathToFileURL } from 'node:url';
4
+import { performance } from 'node:perf_hooks';
5
+import { StorageService } from '../src/core/StorageService.js';
6
+
7
+// Synthetic, deterministic and devoid of real customer data.
8
+export const COUNTS = Object.freeze({ products: 10_000, invoices: 50_000, companies: 5 });
9
+export function syntheticRecord(store, i) {
10
+ const companyId = 'benchmark-c' + (i % COUNTS.companies);
11
+ if (store === 'products') return {
12
+ id: 'bench-p-' + i, companyId, ownerUserId: 'bench-admin',
13
+ name: 'Synthetic product ' + i, code: 'SKU-' + i, sellPrice: 1000 + i
14
+ };
15
+ if (store === 'invoices') return {
16
+ id: 'bench-i-' + i, companyId, ownerUserId: 'bench-admin',
17
+ date: '1405/07/18', kind: 'sale', number: String(i + 1),
18
+ grandTotal: 100000 + i, paidAmount: 0, remaining: 100000 + i,
19
+ isPreInvoice: false
20
+ };
21
+ throw new Error('Unsupported synthetic store');
22
+}
23
+const rounded = n => Math.round(n * 100) / 100;
24
+const elapsed = async fn => {
25
+ const start = performance.now();
26
+ const result = await fn();
27
+ return { ms: rounded(performance.now() - start), result };
28
+};
29
+const percentile = (values, q) => {
30
+ const valuesSorted = [...values].sort((a, b) => a - b);
31
+ return rounded(valuesSorted[Math.min(valuesSorted.length - 1, Math.ceil(q * valuesSorted.length) - 1)]);
32
+};
33
+async function seed(store, count, batchSize = 250) {
34
+ const start = performance.now();
35
+ for (let base = 0; base < count; base += batchSize) {
36
+ const batch = Array.from({ length: Math.min(batchSize, count - base) },
37
+ (_, index) => syntheticRecord(store, base + index));
38
+ await StorageService.transaction(store, async tx => {
39
+ await Promise.all(batch.map(row => tx.putRaw(store, row)));
40
+ });
41
+ }
42
+ return rounded(performance.now() - start);
43
+}
44
+export async function benchmarkA08() {
45
+ await StorageService.init();
46
+ const seedProductsMs = await seed('products', COUNTS.products);
47
+ const seedInvoicesMs = await seed('invoices', COUNTS.invoices);
48
+
49
+ const checks = await Promise.all([
50
+ StorageService.count('products'), StorageService.count('invoices')
51
+ ]);
52
+ if (checks[0] !== COUNTS.products || checks[1] !== COUNTS.invoices) {
53
+ throw Error('Synthetic record counts do not match the target');
54
+ }
55
+
56
+ const queryTimes = [];
57
+ let scopedCount = null;
58
+ for (let i = 0; i < 10; i++) {
59
+ const measured = await elapsed(() => StorageService.getByCompany('invoices', 'benchmark-c0'));
60
+ queryTimes.push(measured.ms);
61
+ scopedCount = measured.result.length;
62
+ if (scopedCount !== 10_000) throw Error('Unexpected company filtering result');
63
+ }
64
+ const snapshot = await elapsed(() => StorageService.exportAll());
65
+ const snapshotCounts = {
66
+ products: snapshot.result.data.products.length,
67
+ invoices: snapshot.result.data.invoices.length
68
+ };
69
+ if (snapshotCounts.products !== 10_000 || snapshotCounts.invoices !== 50_000) {
70
+ throw Error('Backup snapshot counts do not match seed totals');
71
+ }
72
+ // No fixed millisecond budget until an actual machine baseline exists.
73
+ const report = {
74
+ benchmark: 'A08-synthetic-10000-products-50000-invoices-v1',
75
+ timestamp: new Date().toISOString(),
76
+ node: process.version,
77
+ counts: { ...COUNTS, scopedInvoices: scopedCount },
78
+ timingsMs: {
79
+ seedProducts: seedProductsMs, seedInvoices: seedInvoicesMs,
80
+ companyInvoiceRead: { p50: percentile(queryTimes, .5), p95: percentile(queryTimes, .95) },
81
+ fullBackupExport: snapshot.ms
82
+ },
83
+ memoryMiB: {
84
+ rss: rounded(process.memoryUsage().rss / 1024 / 1024),
85
+ heapUsed: rounded(process.memoryUsage().heapUsed / 1024 / 1024)
86
+ },
87
+ note: 'Synthetic fake-indexeddb baseline; not a Windows disk crash or customer performance measurement.'
88
+ };
89
+ return report;
90
+}
91
+if (process.argv[1] && import.meta.url === pathToFileURL(process.argv[1]).href) {
92
+ benchmarkA08().then(report => {
93
+ writeFileSync('a08-benchmark-results.json', JSON.stringify(report, null, 2) + '\n');
94
+ console.log(JSON.stringify(report, null, 2));
95
+ }).catch(error => { console.error(error); process.exitCode = 1; });
96
+}
tests/a08-benchmark-fixtures.test.mjs
new
+18
@@ -0,0 +1,18 @@
1
+import test from 'node:test';
2
+import assert from 'node:assert/strict';
3
+import { COUNTS, syntheticRecord } from '../scripts/a08-benchmark.mjs';
4
+
5
+test('A08 synthetic fixture is stable, bounded and has no personal information', () => {
6
+ assert.deepEqual(COUNTS, { products: 10_000, invoices: 50_000, companies: 5 });
7
+ for (const store of ['products', 'invoices']) {
8
+ const first = syntheticRecord(store, 0);
9
+ const second = syntheticRecord(store, 1);
10
+ assert.deepEqual(syntheticRecord(store, 0), first);
11
+ assert.equal(first.companyId, 'benchmark-c0');
12
+ assert.equal(second.companyId, 'benchmark-c1');
13
+ assert.notEqual(first.id, second.id);
14
+ assert.equal(first.ownerUserId, 'bench-admin');
15
+ }
16
+ assert.equal(syntheticRecord('invoices', 49_999).companyId, 'benchmark-c4');
17
+ assert.throws(() => syntheticRecord('users', 0));
18
+});