Cycles caches bvh in .config/cache folder of Blender, this can lead to huge amount of data never cleaned there
Closed, ResolvedPublic

Description

System Information
windows 8

Blender Version
Broken: all versions of blender
Worked: (optional)

I just have been observing for the past month how my c:\ shrinking in size without any reason, it wen from 30 gb free space to 1 gb.

So I started searching what the issue is, and I found C:\Users\Denis\AppData\Roaming\Blender Foundation\Blender\ where all the majic happened, total size of the folder 40GB!

Inside all blender version folders that have been installed on my PC. From 2.64 to 2.76.

Starting from 2.71 cache folder is massive! I googled what it is, and some report it is when you activate cache bvh, I might have activated that feature in the past, but I definetly did not do that in 2.76 version, which I downloaded just to check if bug behavior is the same as in 2.75a. But that very folder already 5.31GB in size, inside bhv_****** files.

So I do not know if its a bug or something, but to let you know that it happenes. In Blender 2.76 I tested only class room blend from your web page, only once, and it already has 5.3GB of space occupied on c:\, I checked if class room blend has cache bhv enabled, and it does not actually.

;(

Exact steps for others to reproduce the error
Based on a (as simple as possible) attached .blend file with minimum amount of steps

Denis (dns_di) added a project: BF Blender.
Denis (dns_di) set Type to Bug.
Denis (dns_di) added a subscriber: Denis (dns_di).
Bastien Montagne (mont29) changed the title from "cache files eat up a lot of space on C:\ " to "Cycles caches bvh in .config/cache folder of Blender, this can lead to huge amount of data never cleaned there".Sep 19 2015, 10:22 AM
Bastien Montagne (mont29) triaged this task as "Confirmed" priority.

@Sergey Sharybin (sergey) I really do not understand why that bvh data is cached in a persistent dir, and not the temp one? Even worse, that cache dir being part of config folder, it gets copied on each and every new version when you chose to copy previous config…

Oh, yes, you reminded me on the fact that I used on blender 2.76 to copy previous config... so it must have copied cached bhv as well...

Is this task similar to T42376? That was marked as a TODO.

Importing the old BVH caches in the new config is mentioned in the T40669.

I remember searching for them as someone had a hard drive space related problem on the IRC.

Can we just ditch the bvh cache feature? I mean, is it *really* useful after all the BVH build speed-ups that we had? I have seen so many files, where actually the feature caused a slowdown, for example in all the Caminandes files. People use it, even though they have animated content in the scene, making the bvh cache useless. So instead of saving time, checking / reading / writing the cache adds overhead.

@Sergey Sharybin (sergey) Sharrybin

Caching bhv does not really add anything in terms of performance, tested it on many scenes and at most you gain few seconds. BUT getting mesh data, and textures to GPU memory does take a lot of time. Sometimes longer than render time. So the question is if it is possible to avoid constant uploading data to GPU, clearing, again uploading. Can you make that it uploads data once to GPU and keep on rendering frames (in case it is animation)? Because now its very inefficient. I just tested one scene of mine, and it takes 20 seconds to get all the data to GPU and 30 seconds to render, every new frame +20 seconds of the same process!!! I would understand it in case there is some change in the scene and renderer need new info, but in case it is say just turn table, nothing changed just different camera position. So is it doable?

Yes, extending our "Persistent Images (Data)" option is on the todo.

Sounds like it is not very complicated to do, just tell blender not to dump data from the memory :)

Thomas do you have any idea when to expect that feature?

The viewport render already allows something similar: move the viewpoint and/or play animation while rendering with cycles. In this case, it doesn't do the whole reload/calculate BVH/whatever things. WOuld it be possible to get it for the final render too? May be slower to render, but on heavy scene, rendering videos we sometime have 1min30 of prerendering stuff for 30seconds of rendering. So even if the dynamic BVH would make things 50% slower to render, we would render the frames in 45 sec instead of 120. So the whole animation would need 11 days instead of a month. Note that in our tests, the Dynamic BVH is just 20% slower at most, so gain would be much more.
For the current BVH cache, our tests also show that it make things slower. So you can remove it for sure.

I totally support removing the cache BVH feature, especially now with the spatial split building speedups that Sergey has done.

I'm fine with removing cached BVH option as well. There's still some upcoming optimization for the spatial split BVH. Building regular BVH is already just a few percent of overall synchronization time, so it all should be fine.

There'll still be question of cached CUDA and OpenCL kernels. But they're quite small and not so commonly stored on a machine anyway. And think proper way dealing with them would be moving them to XDG's .cache folder. But imlementing this is a separate topic.

If you plan to remove the BVH cache I do hope that the re-rendering process won't be affected in terms of time needed for every subsequent re-render of the same scene. Thank you.

Personally, working only with zipped Blender I do housekeeping regularly to keep my \27x\temp and \27x\cache folders clean.

Furthermore, since I render only on CPU the BVH build up time on re-renders of the same scene (eg. changing samples, but not changing anything about meshes, materials and lights) is faster with the BVH cached, especially with complex scenes with many materials and textures images involved. But hopefully I am worried for nothing.

The copy-previous-setting operator really shouldn't have pick and choose IMHO.
By definitions ~/.config/blender/ is for configuration. (its location on *nix at least).

For now, why not just put the BVH cache in a temp-directory?

I will remove the Cache BVH feature and post a patch for review. :)

@Riccardo: BVH is not related to materials and images, that's a complete different topic and not cached by the BVH cache feature.

@Campbell Barton (campbellbarton), Agree ~/.config isn't a proper way for such kind of cache, and that's why i proposed moving compiled kernels to ~/.cache/blender. But the point is -- BVH Cache option is rather old now and was implemented at the time when BVH was taking quite some time to build. Now we made quite a few optimizations in that area which made BVH build quite a small percentage of all synchronization time, making the cache option just obsolete.

@Riccardo Giovanetti (harvester), BVH build is just a fraction of all sync time, you still need to synchronize textures, update objects states etc. It's not that much of performance gain to cache BVH nowadays. Also, it's rather simple to support keeping BVH in memory, similar to what we do with textures already (Persistent Images option).

@Thomas Dinges (dingto), cool, thanks :)

Well… would rather question the mere existence of 53GBi in ~/.cache/... at all, when dealing such amount of data think you should specify project cache dir, instead of using default one. Also, not sure where does this comes from, afaik Blender does not use that path at all by default (at least, here I have no ~/.cache/Blender). I would assume you defined that path in some user preferences' paths?

I miswrote, I meant '~/.config' not '~/.cache'. I proposed to put cache files in ~/.cache (or somewhere global) and leave ~/.config to just settings and addons. Having cache files in config dir makes no sense.

I have no opinion about removing BVH cache all together - I trust you developers.

@Riccardo Giovanetti (harvester), BVH build is just a fraction of all sync time, you still need to synchronize textures, update objects states etc. It's not that much of performance gain to cache BVH nowadays. Also, it's rather simple to support keeping BVH in memory, similar to what we do with textures already (Persistent Images option).

Nice, so it means only what has changed will be recaclulated/resynced and the rest (99% of the scene) will be as permanent data in GPU/Main memory? It would seriously improve video rendering performance :)

@Thomas Dinges (dingto) and @Sergey Sharybin (sergey), thank you for the explanations about the BVH; in fact it wasn't totally clear to me that "Persistent Images" was related to the texture images, since there is no mention of it as well as other options in the Render | Performance panel inside the online Manual (eg. the Persistent Images option was reported only in the Blender 2.65 Release Notes (Cycles)) . Anyway, that's another story, so go ahead and do your "magic" stuff in Blender.

I think the best place would have been ./blendcache_filename. It is here that all heavy physics cache are stored.
And users are used to move this directory with the blend.

Anyways, dingto will remove it. But if Cycles will cache something in the future, I think that it should be here.