This commit is contained in:
@@ -7,12 +7,10 @@
|
||||
Float32BufferAttribute,
|
||||
Vector3,
|
||||
} from "three";
|
||||
import { decodeFloat } from "@nodes/utils";
|
||||
import { decodeFloat, fastHashArrayBuffer } from "@nodes/utils";
|
||||
import type { PerformanceStore } from "$lib/performance";
|
||||
import { AppSettings } from "$lib/settings/app-settings";
|
||||
|
||||
export let result: Int32Array;
|
||||
|
||||
export let centerCamera: boolean = true;
|
||||
export let perf: PerformanceStore;
|
||||
|
||||
@@ -22,6 +20,22 @@
|
||||
let totalVertices = 0;
|
||||
let totalFaces = 0;
|
||||
|
||||
function fastArrayHash(arr: ArrayBuffer) {
|
||||
let ints = new Uint8Array(arr);
|
||||
|
||||
const sampleDistance = Math.max(Math.floor(ints.length / 100), 1);
|
||||
const sampleCount = Math.floor(ints.length / sampleDistance);
|
||||
|
||||
let hash = new Uint8Array(sampleCount);
|
||||
|
||||
for (let i = 0; i < sampleCount; i++) {
|
||||
const index = i * sampleDistance;
|
||||
hash[i] = ints[index];
|
||||
}
|
||||
|
||||
return fastHashArrayBuffer(hash.buffer);
|
||||
}
|
||||
|
||||
function createGeometryFromEncodedData(
|
||||
encodedData: Int32Array,
|
||||
geometry = new BufferGeometry(),
|
||||
@@ -47,6 +61,10 @@
|
||||
vertexCount * 3,
|
||||
);
|
||||
index = index + vertexCount * 3;
|
||||
let hash = fastArrayHash(vertices);
|
||||
if (geometry.userData?.hash === hash) {
|
||||
return geometry;
|
||||
}
|
||||
|
||||
const normals = new Float32Array(
|
||||
encodedData.buffer,
|
||||
@@ -90,6 +108,7 @@
|
||||
geometry.userData = {
|
||||
vertexCount,
|
||||
faceCount,
|
||||
hash,
|
||||
};
|
||||
|
||||
return geometry;
|
||||
@@ -153,11 +172,11 @@
|
||||
return positions;
|
||||
}
|
||||
|
||||
$: if (result) {
|
||||
export const update = function updateGeometries(result: Int32Array) {
|
||||
let a = performance.now();
|
||||
const inputs = parse_args(result);
|
||||
let b = performance.now();
|
||||
perf?.addPoint("parse-args", b - a);
|
||||
perf?.addPoint("split-result", b - a);
|
||||
|
||||
totalVertices = 0;
|
||||
totalFaces = 0;
|
||||
@@ -185,14 +204,9 @@
|
||||
.filter(Boolean) as BufferGeometry[];
|
||||
b = performance.now();
|
||||
perf?.addPoint("create-geometries", b - a);
|
||||
|
||||
for (const geometry of geometries) {
|
||||
geometry.needsUpdate = true;
|
||||
}
|
||||
|
||||
perf?.addPoint("total-vertices", totalVertices);
|
||||
perf?.addPoint("total-faces", totalFaces);
|
||||
}
|
||||
};
|
||||
</script>
|
||||
|
||||
<Canvas>
|
||||
|
@@ -1,5 +1,5 @@
|
||||
import type { Graph, NodeRegistry, NodeDefinition, RuntimeExecutor, NodeInput } from "@nodes/types";
|
||||
import { concatEncodedArrays, encodeFloat, fastHashArray } from "@nodes/utils"
|
||||
import { concatEncodedArrays, encodeFloat, fastHashArrayBuffer } from "@nodes/utils"
|
||||
import { createLogger } from "./helpers";
|
||||
import type { RuntimeCache } from "@nodes/types";
|
||||
import type { PerformanceStore } from "./performance";
|
||||
@@ -138,7 +138,7 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
const [outputNode, nodes] = await this.addMetaData(graph);
|
||||
let b = performance.now();
|
||||
|
||||
this.perf?.addPoint("metadata", b - a);
|
||||
this.perf?.addPoint("collect-metadata", b - a);
|
||||
|
||||
/*
|
||||
* Here we sort the nodes into buckets, which we then execute one by one
|
||||
@@ -211,7 +211,10 @@ export class MemoryRuntimeExecutor implements RuntimeExecutor {
|
||||
b = performance.now();
|
||||
this.perf?.addPoint("encoded-inputs", b - a);
|
||||
|
||||
let inputHash = `node-${node.id}-${fastHashArray(encoded_inputs)}`;
|
||||
a = performance.now();
|
||||
let inputHash = `node-${node.id}-${fastHashArrayBuffer(encoded_inputs)}`;
|
||||
b = performance.now();
|
||||
this.perf?.addPoint("hash-inputs", b - a);
|
||||
let cachedValue = this.cache?.get(inputHash);
|
||||
if (cachedValue !== undefined) {
|
||||
log.log(`Using cached value for ${node_type.id || node.id}`);
|
||||
|
Reference in New Issue
Block a user