Skip to content

fix: add global model cache to prevent duplicate loads and browser lag - #923

Open
khozakhulile27-netizen wants to merge 3 commits into
tscircuit:mainfrom
khozakhulile27-netizen:fix/93-global-model-cache
Open

fix: add global model cache to prevent duplicate loads and browser lag#923
khozakhulile27-netizen wants to merge 3 commits into
tscircuit:mainfrom
khozakhulile27-netizen:fix/93-global-model-cache

Conversation

@khozakhulile27-netizen

Copy link
Copy Markdown

Closes #93

Problem

The load3DModel utility had no caching, so the same 3D model file (STL/OBJ/GLTF/WRL) would be fetched and parsed multiple times when multiple components share the same model URL. This caused duplicate network requests and redundant Three.js geometry creation, making the browser laggy.

Fix

Added a window.TSCIRCUIT_MODEL_CACHE global Map that stores in-flight load promises. Before fetching, the function checks the cache. If a cached result exists, it clones the Object3D (so each usage gets its own independent scene graph node) instead of re-fetching.

This follows the same pattern already used in use-global-obj-loader.ts.

@vercel

vercel Bot commented May 23, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
3d-viewer Ready Ready Preview, Comment May 23, 2026 7:20am

Request Review

@khozakhulile27-netizen

Copy link
Copy Markdown
Author

/claim #93

This PR adds a global in-memory model cache (window.TSCIRCUIT_MODEL_CACHE) to load3DModel to prevent the same model being fetched and parsed multiple times, eliminating the lag when multiple components use the same 3D model.

@khozakhulile27-netizen

Copy link
Copy Markdown
Author

✅ All CI checks passing (format-check, type-check, test, Vercel). This PR is ready for review and merge.

@khozakhulile27-netizen

Copy link
Copy Markdown
Author

/attempt #93

@khozakhulile27-netizen

Copy link
Copy Markdown
Author

Shibosoftwaredev please review

@MikeGarciaAGM MikeGarciaAGM left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good. Adding a global model cache is a practical way to avoid duplicate loads and the change stays well contained.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Improve 3d model loading to avoid laggy browser

2 participants