mirror of
https://github.com/tinygrad/tinygrad.git
synced 2026-08-29 12:36:07 +00:00
cache viz worker at launch (#9589)
This commit is contained in:
@@ -9,7 +9,12 @@ function intersectRect(r1, r2) {
|
||||
}
|
||||
|
||||
const allWorkers = [];
|
||||
window.renderGraph = function(graph, additions, name) {
|
||||
let workerUrl = null;
|
||||
window.renderGraph = async function(graph, additions, name) {
|
||||
if (workerUrl == null) {
|
||||
const resp = await Promise.all(["/assets/dagrejs.github.io/project/dagre/latest/dagre.min.js","/lib/worker.js"].map(u => fetch(u)));
|
||||
workerUrl = URL.createObjectURL(new Blob([(await Promise.all(resp.map((r) => r.text()))).join("\n")], { type: "application/javascript" }));
|
||||
}
|
||||
while (allWorkers.length) {
|
||||
const { worker, timeout } = allWorkers.pop();
|
||||
worker.terminate();
|
||||
@@ -22,7 +27,7 @@ window.renderGraph = function(graph, additions, name) {
|
||||
d3.select("#bars").html("");
|
||||
|
||||
// ** start calculating the new layout (non-blocking)
|
||||
worker = new Worker("/lib/worker.js");
|
||||
worker = new Worker(workerUrl);
|
||||
const progressMessage = document.querySelector(".progress-message");
|
||||
const timeout = setTimeout(() => {
|
||||
progressMessage.style.display = "block";
|
||||
|
||||
@@ -1,5 +1,3 @@
|
||||
importScripts("../assets/dagrejs.github.io/project/dagre/latest/dagre.min.js");
|
||||
|
||||
const NODE_PADDING = 10;
|
||||
const LINE_HEIGHT = 14;
|
||||
const canvas = new OffscreenCanvas(0, 0);
|
||||
|
||||
Reference in New Issue
Block a user