SPB Git

Repository Public

perf.spec.ts 7.8 KB 167 lines typescript

1/**2 * =============================================================================3 *                  SP BOUCHER | SOFTWARE & RESEARCH4 *             ARTIFICIAL INTELLIGENCE • FINANCE • ENGINEERING5 * =============================================================================6 *7 * Project          : KA Maps Engine8 * File             : sdk/web/tests/e2e/perf.spec.ts9 * Module           : sdk10 * Repository       : https://git.spboucher.ai/ka-maps-engine11 * Created          : 2026-12-0112 * Last Modified    : 2026-12-0113 *14 * Author           : Simon-Pierre Boucher15 * Position         : Professor of Finance16 * Institution      : Université du Québec en Outaouais (UQO)17 * Organization     : SP Boucher18 * Website          : https://spboucher.ai19 * Git              : https://git.spboucher.ai20 *21 * Preferred Contact: support@spboucher.ai22 * Development      : dev@spboucher.ai23 * Support          : support@spboucher.ai24 * Security/Admin   : admin@spboucher.ai25 *26 * Copyright (c) 202627 * Simon-Pierre Boucher28 * All rights reserved where applicable. This file is governed by the29 * applicable project license, copyright notices and relevant law.30 * Existing third-party rights and notices remain unaffected.31 *32 * License          : None specified (no license file in this repository)33 *34 * Do not embed credentials, private keys, access tokens,35 * certificates or confidential personal information.36 *37 * =============================================================================38 * END OF SP BOUCHER SOURCE HEADER39 * =============================================================================40 */4142// Mesures (temps de chargement, cadence, mémoire) écrites dans test-results/perf/<projet>.json, puis43// reportées dans docs/PERFORMANCE_BENCHMARKS.md. Les seuils vérifiés ici sont des garde-fous larges ;44// les chiffres publiés sont ceux du fichier.45import { expect, test, type Page } from '@playwright/test';46import { mkdirSync, writeFileSync } from 'node:fs';47import { openDemo, settle, gpuMessages } from './helpers.js';4849// Garde permanente : aucun avertissement ni erreur de validation wgpu / WebGPU / WGSL / WebGL dans la console,50// quel que soit l'essai (un module de shader refusé rend la carte noire sans faire échouer la compilation).51test.afterEach(async ({ page }) => {52  expect(gpuMessages(page), 'validation graphique dans la console').toEqual([]);53});5455async function fpsDuring(page: Page, ms: number, start: () => Promise<void>) {56  await start();57  await page.waitForTimeout(400); // montée en régime58  const a = await page.evaluate(() => ({ f: window.kaMap!.getStats().framesRendered, t: performance.now() }));59  await page.waitForTimeout(ms);60  const b = await page.evaluate(() => ({ f: window.kaMap!.getStats().framesRendered, t: performance.now(), s: window.kaMap!.getStats(), p: window.kaMap!.getPerf() }));61  return {62    fps: Number((((b.f - a.f) * 1000) / (b.t - a.t)).toFixed(1)),63    frameCpuMs: Number(b.s.frameCpuMs.toFixed(2)),64    engineFrameMs: Number(b.p.frameMs.toFixed(2)),65    drawCalls: b.p.drawCalls,66    triangles: b.p.triangles,67    tiles: b.p.tiles,68    quality: b.p.quality,69  };70}7172test('mesures : chargement, cadence 2D et 3D, mémoire', async ({ page }, testInfo) => {73  test.setTimeout(180_000);74  // Chargement à froid (contexte neuf : ni cache HTTP ni IndexedDB).75  const t0 = Date.now();76  await openDemo(page, testInfo, { layers: '', reduced: 0 });77  const coldReadyMs = Date.now() - t0;78  await settle(page);79  const cold = await page.evaluate(() => {80    const s = window.kaMap!.getStats();81    const nav = performance.getEntriesByType('navigation')[0] as PerformanceNavigationTiming;82    const wasm = performance.getEntriesByType('resource').find((r) => r.name.endsWith('.wasm')) as PerformanceResourceTiming | undefined;83    return {84      domContentLoadedMs: Math.round(nav.domContentLoadedEventEnd),85      engineLoadMs: Math.round(s.engineLoadMs),86      createMs: Math.round(s.createMs),87      wasmFetchMs: wasm ? Math.round(wasm.duration) : null,88      tilesFetched: s.fetch.networkTiles,89      terrainFetched: s.fetch.networkTerrain,90      tileBytes: s.fetch.bytes,91      workers: s.workers?.alive ?? 0,92      tilesBuilt: s.workers?.built ?? 0,93      avgBuildMs: s.workers && s.workers.built ? Number((s.workers.buildMs / s.workers.built).toFixed(1)) : null,94      backend: s.backend,95      adapter: window.kaMap!.getAdapterInfo().name,96      userAgent: navigator.userAgent,97      dpr: devicePixelRatio,98      canvas: [(window.kaMap!.getCanvas() as HTMLCanvasElement).width, (window.kaMap!.getCanvas() as HTMLCanvasElement).height],99    };100  });101  // Chargement à chaud (cache HTTP du binaire + tuiles dans IndexedDB).102  await page.evaluate(() => window.kaMap!.offline.flush());103  const t1 = Date.now();104  await page.reload();105  await page.waitForFunction(() => window.kaDemo?.ready, null, { timeout: 60_000 });106  const warmReadyMs = Date.now() - t1;107  await settle(page);108  const warm = await page.evaluate(() => ({ cacheHits: window.kaMap!.getStats().fetch.cacheHits, network: window.kaMap!.getStats().fetch.networkTiles, createMs: Math.round(window.kaMap!.getStats().createMs), engineLoadMs: Math.round(window.kaMap!.getStats().engineLoadMs) }));109110  // Cadence 2D : déplacement et zoom continus au centre-ville de Montréal (z14 ↔ z15,5).111  const fps2d = await fpsDuring(page, 5000, async () => {112    await page.evaluate(() => {113      const m = window.kaMap!;114      m.setQuality('high');115      let i = 0;116      const next = () => {117        if (m.isDestroyed || (window as any).__stopAnim) return;118        i++;119        m.easeTo({ center: [-73.5674 + 0.012 * Math.sin(i), 45.5019 + 0.008 * Math.cos(i * 1.3)], zoom: i % 2 ? 15.5 : 14, bearing: 0 }, { duration: 1100, easing: 'linear' });120      };121      (window as any).__animOff = m.on('moveend', next);122      next();123    });124  });125  await page.evaluate(() => {126    (window as any).__stopAnim = true;127    (window as any).__animOff();128    window.kaMap!.stop();129  });130  await settle(page);131132  // Cadence 3D : survol circulaire du centre-ville, volumes et ombres (qualité haute).133  await page.evaluate(() => window.kaMap!.jumpTo({ center: [-73.5674, 45.5019], zoom: 15.5 }));134  await settle(page);135  const fps3d = await fpsDuring(page, 5000, async () => {136    await page.evaluate(() => window.kaMap!.orbit({ center: [-73.5674, 45.5019], zoom: 15.6, pitch: 60, turns: 1, duration: 14000 }));137  });138  await page.evaluate(() => window.kaMap!.stop());139  await settle(page);140  // 3D avec toutes les couches d'application.141  await page.evaluate(() => {142    for (const n of window.kaDemo.layerNames) window.kaDemo.setLayer(n, true);143  });144  await settle(page);145  const fps3dLayers = await fpsDuring(page, 4000, async () => {146    await page.evaluate(() => window.kaMap!.orbit({ center: [-73.5674, 45.5019], zoom: 14.2, pitch: 58, turns: 1, duration: 14000 }));147  });148  await page.evaluate(() => window.kaMap!.stop());149  await settle(page);150151  const memory = await page.evaluate(() => {152    const s = window.kaMap!.getStats();153    return { wasmMb: Number((s.wasmMemoryBytes / 1048576).toFixed(1)), jsHeapMb: s.jsHeapBytes ? Number((s.jsHeapBytes / 1048576).toFixed(1)) : null, gpuEstimateMb: Number((window.kaMap!.getPerf().memory / 1048576).toFixed(1)) };154  });155156  const result = { project: testInfo.project.name, date: new Date().toISOString(), viewport: page.viewportSize(), coldReadyMs, warmReadyMs, cold, warm, fps2d, fps3d, fps3dLayers, memory };157  mkdirSync('test-results/perf', { recursive: true });158  writeFileSync(`test-results/perf/${testInfo.project.name}.json`, JSON.stringify(result, null, 2));159  await testInfo.attach('perf.json', { body: JSON.stringify(result, null, 2), contentType: 'application/json' });160  console.log(`PERF ${JSON.stringify(result)}`);161162  expect(coldReadyMs).toBeLessThan(20_000);163  expect(warm.network).toBe(0);164  expect(fps2d.fps).toBeGreaterThan(20);165  expect(fps3d.fps).toBeGreaterThan(15);166});167
Files main
Menu

Theme