feat: move registry and runtime into separate packages
All checks were successful
Deploy to GitHub Pages / build_site (push) Successful in 2m32s

This commit is contained in:
2024-05-05 15:11:53 +02:00
parent f4853821d4
commit a01a409b97
29 changed files with 205 additions and 156 deletions

View File

@@ -3,7 +3,7 @@
import { humanizeNumber } from "$lib/helpers";
import { Checkbox } from "@nodes/ui";
import localStore from "$lib/helpers/localStore";
import { type PerformanceData } from "./store";
import { type PerformanceData } from "@nodes/utils";
import BarSplit from "./BarSplit.svelte";
export let data: PerformanceData;

View File

@@ -2,15 +2,13 @@
import { humanizeDuration, humanizeNumber } from "$lib/helpers";
import localStore from "$lib/helpers/localStore";
import SmallGraph from "./SmallGraph.svelte";
import type { PerformanceData, PerformanceStore } from "./store";
import type { PerformanceData, PerformanceStore } from "@nodes/utils";
export let store: PerformanceStore;
const open = localStore("node.performance.small.open", {
runtime: false,
fps: false,
vertices: false,
faces: false,
});
$: vertices = $store?.at(-1)?.["total-vertices"][0] || 0;
@@ -54,29 +52,15 @@
</tr>
{/if}
<tr on:click={() => ($open.vertices = !$open.vertices)}>
<td>{$open.vertices ? "-" : "+"} vertices </td>
<tr>
<td>vertices </td>
<td>{humanizeNumber(vertices || 0)}</td>
</tr>
{#if $open.vertices}
<tr>
<td colspan="2">
<SmallGraph points={getPoints($store, "total-vertices")} />
</td>
</tr>
{/if}
<tr on:click={() => ($open.faces = !$open.faces)}>
<td>{$open.faces ? "-" : "+"} faces </td>
<tr>
<td>faces </td>
<td>{humanizeNumber(faces || 0)}</td>
</tr>
{#if $open.faces}
<tr>
<td colspan="2">
<SmallGraph points={getPoints($store, "total-faces")} />
</td>
</tr>
{/if}
</table>
</div>

View File

@@ -1,2 +1 @@
export * from "./store";
export { default as PerformanceViewer } from "./PerformanceViewer.svelte";

View File

@@ -1,97 +0,0 @@
import { readable, type Readable } from "svelte/store";
export type PerformanceData = Record<string, number[]>[];
export interface PerformanceStore extends Readable<PerformanceData> {
startRun(): void;
stopRun(): void;
addPoint(name: string, value?: number): void;
endPoint(name?: string): void;
mergeData(data: PerformanceData[number]): void;
get: () => PerformanceData;
}
export function createPerformanceStore(id?: string): PerformanceStore {
let data: PerformanceData = [];
let currentRun: Record<string, number[]> | undefined;
let temp: Record<string, number> | undefined;
let lastPoint: string | undefined;
let set: (v: PerformanceData) => void;
const { subscribe } = readable<PerformanceData>([], (_set) => {
set = _set;
});
function startRun() {
if (currentRun) return;
currentRun = {};
lastPoint = undefined;
temp = {
start: performance.now()
}
}
function stopRun() {
if (currentRun && temp) {
currentRun["total"] = [performance.now() - temp.start];
data.push(currentRun);
data = data.slice(-100);
currentRun = undefined;
temp = undefined;
if (set) set(data);
}
}
function addPoint(name: string, value?: number) {
if (!currentRun) return;
if (value === undefined) {
if (temp) {
lastPoint = name;
temp[name] = performance.now();
}
} else {
currentRun[name] = currentRun[name] || [];
currentRun[name].push(value);
}
}
function get() {
return data;
}
function mergeData(newData: PerformanceData[number]) {
let r = currentRun;
if (!r) return;
Object.keys(newData).forEach((name) => {
if (name in r) {
r[name].push(...newData[name]);
} else {
r[name] = newData[name];
}
});
}
function endPoint(name = lastPoint) {
if (name === lastPoint) lastPoint = undefined;
if (name && currentRun && temp && name in temp) {
currentRun[name] = currentRun[name] || [];
currentRun[name].push(performance.now() - temp[name]);
delete temp[name];
}
}
return {
subscribe,
startRun,
stopRun,
addPoint,
endPoint,
mergeData,
get
}
}