-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Allow creation of a CacheConfig without loading from a file #10665
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow creation of a CacheConfig without loading from a file #10665
Conversation
Label Messager: wasmtime:configIt looks like you are changing Wasmtime's configuration options. Make sure to
To modify this label's message, edit the To add new label messages or remove existing label messages, edit the |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for this! FWIW the caching system hasn't really been substantially touched since its inception in 2019 so while reading over this I've noticed some other things that I think might be worth implementing, but I also don't want to hitch you with unnecessary work you don't have time to do. In that sense I'd like to see if you're interested in some of these adjacent cleanups perhaps? If not no worries we can go ahead and land this and I can work on some cleanups later.
- All
Config::cache_*
methods I think can now be deleted in favor of your newcache_config
method with a minor adjustment to takeOption<CacheConfig>
whereNone
means "disable". We could then delegate file parsing and "load default" to methods onCacheConfig
which are already there asCacheConfig::from_file
- For the worker I think ideally creating a
Config
wouldn't actually spawn anything. Instead I think it would be best to defer that toEngine
-creation time. For example we'd have some code in the engine creation where it'd callconfig.cache_config.spawn()
or similar. - To mirror configuration in Wasmtime we could perhaps rename
wasmtime_cache::CacheConfig
toCache
and then renamewasmtime_cache::CacheConfigBuilder
toCacheConfig
. Basically centralizing on "Thing" is the actual thing that was made where "ThingConfig" is configuration to produce the Thing. That means the new method could perhaps beConfig::cache(&mut self, cache: Option<Cache>)
.
Would you be up for those changes as well? I've got a few comments on this change in particular below too as well, and again I'm happy to defer the above improvements for later if you'd prefer to not take that on.
@alexcrichton thanks for the thorough review! |
c2d3d6f
to
22020b4
Compare
455e8dd
to
5b8657c
Compare
@alexcrichton Ok I think it is ready for review again. I also think this is all a lot, lot nicer than before, as well as being more flexible. Notes of breaking changes:
Other notable changes:
The enabled flag felt kind of weird to leave as an option, since now there is either a However, because of If we want to support this old behavior, I am fine with doing so. Users who embed wasmtime will need to update their code regardless, so this might be acceptable. Happy to address any and all feedback, I went in circles a bit trying out different things here, so there is likely room for improvement! |
A new `cache_config(Option<CacheConfig>)` method replaces multiple methods for controlling module caching. Now `None` disables caching, and users can directly provide a cache config or load one from a file.
4c03661
to
dd1f91d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks again for your work on this! All the changes here look reasonable to me, and thinking about it I think it's reasonable to leave deny_unknown_fields
and drop enabled = true
as well. That's a pretty old setting which predated the current CLI flags and configuration system, so I think it's reasonable to take this time to bring it forward to the current era.
The documentation seems outdated https://github.com/bytecodealliance/wasmtime/blob/0fabedfece020cab90124768c3dc94b8d95ca4ab/docs/cli-cache.md#setting-enabled |
@dev-null-undefined good catch! Made a follow up PR here: #10859 |
Addresses issue #10638
Since creating a
CacheConfig
also creates the worker thread, I opted for a Builder pattern, so that this worker thread, validation, and default values could be created in thebuild
method, much like what happens when deserializing from a file.If there is a preferred alternate approach though, let me know.
One thing that came to mind is that we may make it easier to create these worker threads, because it is easier to construct the
CacheConfig
, but since these threads get cleaned up once theCacheConfig
is dropped, maybe this is not an issue?I'm also not sure if there is any danger in having multiple
CacheConfig
s pointing to the same directory in terms of the worker threads. But this issue could have existed with multipleConfig
with the same default config, so I assume this is not a huge issue.If there are any changes needed, let me know, especially around coding guidelines or best testing practices.
Thanks!