jalberse / shimmer

Physically based rendering in Rust
Apache License 2.0
33 stars 0 forks source link

Reduce memory consumption #80

Open jalberse opened 3 months ago

jalberse commented 3 months ago

Rendering the large kroken scene shows large memory usage (~36GB). Other renderers are able to handle with about ~18GB.

Texture + Transform + Mesh caches should be able to reduce the size, but I'm not sure if that's the main culprit.

I haven't kept a close eye on the size of key Enums. Enums are the size of the largest variant + the discriminant. If there's a large variant in our key types, we may be wasting a lot of space. We could solve that by storing a pointer in the variant, rather than the type itself - or perhaps switch to a dyn trait object over enum dispatch?

This adds a layer of indirection when resolving function calls, but would save space. The performance gain from lower memory usage is probably worthwhile, though - would need to benchmark. We might only do this for some of our types, rather than all of them.

It might also be worth adding logging which tracks the memory used for various types, so we can measure the impact of this change and identify pain points easier.

jalberse commented 3 months ago

Issue #69 may also be important. I'll often store a usize, including in Tris, but that may be unnecessarily large depending on the system. Switching to a u32 would likely reduce memory usage. Try switching that in Tri and BilinearPatch and measure the impact. That should be our first port of call

jalberse commented 3 months ago

Issue #81 would probably be a big win as well. I think triangles are likely taking up the most memory in the system (I need to measure this stuff).

jalberse commented 2 months ago

Another to look at (again, I need to actually measure) is the fact that our Enums are the size of their largest variant. Storing pointers to large variants instead will introduce a level of indirection, but reduce memory consumption.