From fb329eff80cd156e1e3ee4b068f09ae1f035a25b Mon Sep 17 00:00:00 2001 From: Aryan Gupta Date: Mon, 29 Jun 2026 22:16:08 +1000 Subject: [PATCH] perf: Add performance toggle and verify everything works. --- esbuild.config.mjs | 3 ++- src/view.ts | 36 ++++++++++-------------------------- 2 files changed, 12 insertions(+), 27 deletions(-) diff --git a/esbuild.config.mjs b/esbuild.config.mjs index 2fae0d3..29385d6 100644 --- a/esbuild.config.mjs +++ b/esbuild.config.mjs @@ -33,10 +33,11 @@ const context = await esbuild.context({ "@lezer/lr", ...builtins], format: "cjs", - target: "es2022", + target: "es2018", logLevel: "info", sourcemap: prod ? false : "inline", treeShaking: true, + mainFields: ["module", "main"], outfile: "main.js", minify: prod, }); diff --git a/src/view.ts b/src/view.ts index 288b001..e0c14b8 100644 --- a/src/view.ts +++ b/src/view.ts @@ -38,7 +38,7 @@ export class Graph3DView extends ItemView { private readonly RAYCAST_CULL_DISTANCE = 800; private nodeMeshes = new WeakMap(); - private nodeSprites = new WeakMap(); + private nodeSprites = new Map(); private highlightedNodes = new Set(); private highlightedLinks = new Set(); @@ -1323,42 +1323,27 @@ export class Graph3DView extends ItemView { if (cachedNodeInfo && cachedNodeInfo.mtime === file.stat.mtime) { node = cachedNodeInfo.node; - // If search or text groups require content, but cached node doesn't have it, load it - if (node.type === NodeType.File && needsContent && !node.content) { - let content = ''; - let lowerCaseContent = ''; - const cachedContent = this.fileContentCache.get(file.path); - if (cachedContent && cachedContent.mtime === file.stat.mtime) { - content = cachedContent.content; - lowerCaseContent = cachedContent.lowerCaseContent; - } else { - content = await this.app.vault.cachedRead(file); - lowerCaseContent = content.toLowerCase(); - this.fileContentCache.set(file.path, { mtime: file.stat.mtime, content, lowerCaseContent }); - } - node.content = content; - node.lowerCaseContent = lowerCaseContent; + // If search or text groups require content, but cached content doesn't exist, load it + if (node.type === NodeType.File && needsContent && !this.fileContentCache.has(file.path)) { + const content = await this.app.vault.cachedRead(file); + const lowerCaseContent = content.toLowerCase(); + this.fileContentCache.set(file.path, { mtime: file.stat.mtime, content, lowerCaseContent }); } } else { const cache = this.app.metadataCache.getFileCache(file); const tags = cache ? (getAllTags(cache) || []).map(t => t.startsWith('#') ? t.substring(1) : t) : []; const type = file.extension === 'md' ? NodeType.File : NodeType.Attachment; - let content = ''; - let lowerCaseContent = ''; if (type === NodeType.File && needsContent) { const cachedContent = this.fileContentCache.get(file.path); - if (cachedContent && cachedContent.mtime === file.stat.mtime) { - content = cachedContent.content; - lowerCaseContent = cachedContent.lowerCaseContent; - } else { - content = await this.app.vault.cachedRead(file); - lowerCaseContent = content.toLowerCase(); + if (!cachedContent || cachedContent.mtime !== file.stat.mtime) { + const content = await this.app.vault.cachedRead(file); + const lowerCaseContent = content.toLowerCase(); this.fileContentCache.set(file.path, { mtime: file.stat.mtime, content, lowerCaseContent }); } } - node = { id: file.path, name: file.basename, filename: file.name, type, tags, content, lowerCaseContent }; + node = { id: file.path, name: file.basename, filename: file.name, type, tags }; this.processedNodes.set(file.path, { node, mtime: file.stat.mtime }); } @@ -1367,7 +1352,6 @@ export class Graph3DView extends ItemView { }); await Promise.all(workers); - const allLinks: { source: string, target: string }[] = []; const existingLinks = new Set();