question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

WebGLRenderer: Use faster program cache key computation.

See original GitHub issue

I’ve recently did a profile of my project, haven’t done that in 4-5 months, since then three.js version has been upgraded several times. Currently on 0.132.2

So, profile shows up that getProgramCacheKey takes up close to 20% of the entire time: image

For a bit more context, this is in the scope of the entire game, with particle simulation, IK, sound and a bunch of other stuff going on. Not just pure rendering. Here’s a screenshot of what’s being rendered: image

Here’s the WebGLRenderer.info: image

If you have a look at the cache key computation code, there’s a lot wrong there. It’s building an array of strings, that’s a lot of allocation, and then there’s array.join() which results in another string being created. All of that, just to throw the result away in the end (since no new materials are created during profiling period).

I propose offering an override for the cache keys, or building keys in a way that avoids much of the allocation effort. Also, doing equality check on material against what’s already cached can be done without materializing this “cache key” at all. I understand that it’s “simple” to do what’s currently being done, and I understand that doing what I propose is less easy, but we’re talking about 20% of the CPU time being wasted on an application that’s hardly pure rendering.

As an alternative - perhaps offer an override for cache key computation, something like “customComputeMaterialCacheKey”, that would be dirty, but it would allow users like me to work around the issue.

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Reactions:5
  • Comments:30 (19 by maintainers)

github_iconTop GitHub Comments

6reactions
donmccurdycommented, Sep 22, 2021

I’m little worried about the added complexity of multiple cache keys, but one option might be to keep a cheaper “fastProgramCacheKey” to map a single material to its program variants. Since there are not many possible combinations there, it could just be a cheaper bit mask instead of a string. For example:

const cacheKey = SKINNING & VERTEX_TANGENTS & MORPH_TARGETS;
5reactions
gero3commented, Dec 28, 2021

@gonnavis I’ll have a look at your example to see what’s going on between version r129 vs r136.

Read more comments on GitHub >

github_iconTop Results From Across the Web

WebGLRenderer – three.js docs
The WebGL renderer displays your beautifully crafted scenes using WebGL. Constructor. WebGLRenderer( parameters : Object ). parameters - (optional) object with ...
Read more >
Efficiently rendering glTF models | WebGPU ... - GitHub Pages
WebGPU is a new, modern API for using the GPU on the web more efficiently ... Once we have a key, we can...
Read more >
Speed up Your Canvas Operations with a Web Worker
Software Engineer working on performance metrics at Google ... Here I use OffscreenCanvas to calculate a gradient color in a worker:
Read more >
Team:Munich/Hardware/threeJS - iGEM 2018
// We compute the minimum and maximum dot product values. If those values // are on the same side (back or front) of...
Read more >
Application Data Caching - Quarkus
When a method annotated with @CacheResult is invoked, Quarkus will compute a cache key and use it to check in the cache whether...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found