aardvark-platform / aardvark.base

Aardvark.Base is the foundation of the open-source Aardvark Platform for visual computing, real-time graphics, and visualization.
https://aardvarkians.com/
Apache License 2.0
153 stars 9 forks source link

Plugin cache conflicts #49

Closed luithefirst closed 3 years ago

luithefirst commented 3 years ago

When looking at the aardvark plugins cache it is written to a file with AssemblyName + "_plugins.bin", while all other cache files also contain a Guid. This causes conflicts when starting different deployment versions of the same application and results in a lot of cache misses and slow startup time. It would be cleaner to also add some kind of version or assembly guid there.

krauthaufen commented 3 years ago

Good idea, we should also make sure our cache files don't end up in the temp folder anymore (something like AppData) since linux/macos tend to empty the temp folder on reboot, etc.

luithefirst commented 3 years ago

An issue by adding a Guid would be that during development this would change every time when compiling and we would always have slow startup times. It looks like the current mechanism is acceptable. When it is possible to configure the cache directory (#48) and assuming that data of major application releases are separated, conflicts would be avoided at least in this case. Anyway, it would be worth reconsidering the caching architecture.

The Guid in the other cases is also only a hash of the "query" (e.g. all types with IFieldCodeable) and not to separate caches for different assembly versions. So the Aardvark caches are only valid for a single version either and when starting a different application version are overwritten. For me it looks like this can be extended and we could include the version into the filename instead of the header of the cache file and the cache file content would only be a list of types or whatever the "query" is.

hyazinthh commented 3 years ago

Basically, we have two different types of files in the cache directory:

@luithefirst so your suggestion is to add the assembly version for the query caches but not the plugin location caches? I don't really see how adding the version to the plugin location caches is a problem. Does simply compiling increment the assembly version in your use cases? In this case, incorporating the version into the name would also lead to cache misses for the introspection cache of your assembly.

As for the caching system in general, I wonder if this loose file-based structure is a good idea if we discriminate between versions as well. My cache directory already contains over 1000 files, can that become a problem?

Good idea, we should also make sure our cache files don't end up in the temp folder anymore (something like AppData) since linux/macos tend to empty the temp folder on reboot, etc.

Regarding Environment.SpecialFolder.ApplicationData, where does this point on other platforms? On Ubuntu it seems to point to ~/.config which should be perfectly fine.

luithefirst commented 3 years ago

Regarding the loose file-based structure: As we also typically have an even larger number of shader caches, I did not saw this as an issue so far.

hyazinthh commented 3 years ago

https://github.com/aardvark-platform/aardvark.base/commit/65a6d1ab4e70b8ebd9a383266d39b8f9239d754f adds a new static class CachingProperties to set the cache directory. Maybe it should be possible to set different naming schemes there as well, since there does not seem to be a single correct solution. E.g. you could set whether the version or the GUID is used for the cache names. The default could be GUID for introspection and version for plugins.

hyazinthh commented 3 years ago

I implemented configurable naming schemes in https://github.com/aardvark-platform/aardvark.base/commit/7cd190ca388480c131ed32558b840488d4754616. Can be modified by setting CachingProperties.PluginsCacheFileNaming and CachingProperties.IntrospectionCacheFileNaming. By default, introspection cache files are named based on the assembly file modification date and plugins cache files based on assembly version.

luithefirst commented 3 years ago

I guess this is the best solution for now as it does not change anything fundamentally