benbrandt opened PR #10665 from benbrandt:expose-cache-config to bytecodealliance:main:
Addresses issue #10638
Since creating a
CacheConfigalso creates the worker thread, I opted for a Builder pattern, so that this worker thread, validation, and default values could be created in thebuildmethod, 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 theCacheConfigis dropped, maybe this is not an issue?I'm also not sure if there is any danger in having multiple
CacheConfigs pointing to the same directory in terms of the worker threads. But this issue could have existed with multipleConfigwith 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!
<!--
Please make sure you include the following information:
If this work has been discussed elsewhere, please include a link to that
conversation. If it was discussed in an issue, just mention "issue #...".Explain why this change is needed. If the details are in an issue already,
this can be brief.Our development process is documented in the Wasmtime book:
https://docs.wasmtime.dev/contributing-development-process.htmlPlease ensure all communication follows the code of conduct:
https://github.com/bytecodealliance/wasmtime/blob/main/CODE_OF_CONDUCT.md
-->
benbrandt requested alexcrichton for a review on PR #10665.
benbrandt requested wasmtime-core-reviewers for a review on PR #10665.
benbrandt updated PR #10665.
github-actions[bot] commented on PR #10665:
Label Messager: wasmtime:config
It looks like you are changing Wasmtime's configuration options. Make sure to
complete this check list:
[ ] If you added a new
Configmethod, you wrote extensive documentation for
it.<details>
Our documentation should be of the following form:
```text
Short, simple summary sentence.More details. These details can be multiple paragraphs. There should be
information about not just the method, but its parameters and results as
well.Is this method fallible? If so, when can it return an error?
Can this method panic? If so, when does it panic?
Example
Optional example here.
```</details>
[ ] If you added a new
Configmethod, or modified an existing one, you
ensured that this configuration is exercised by the fuzz targets.<details>
For example, if you expose a new strategy for allocating the next instance
slot inside the pooling allocator, you should ensure that at least one of our
fuzz targets exercises that new strategy.Often, all that is required of you is to ensure that there is a knob for this
configuration option in [wasmtime_fuzzing::Config][fuzzing-config] (or one
of its nestedstructs).Rarely, this may require authoring a new fuzz target to specifically test this
configuration. See [our docs on fuzzing][fuzzing-docs] for more details.</details>
[ ] If you are enabling a configuration option by default, make sure that it
has been fuzzed for at least two weeks before turning it on by default.[fuzzing-config]: https://github.com/bytecodealliance/wasmtime/blob/ca0e8d0a1d8cefc0496dba2f77a670571d8fdcab/crates/fuzzing/src/generators.rs#L182-L194
[fuzzing-docs]: https://docs.wasmtime.dev/contributing-fuzzing.html
<details>
To modify this label's message, edit the <code>.github/label-messager/wasmtime-config.md</code> file.
To add new label messages or remove existing label messages, edit the
<code>.github/label-messager.json</code> configuration file.</details>
alexcrichton submitted PR review:
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_configmethod with a minor adjustment to takeOption<CacheConfig>whereNonemeans "disable". We could then delegate file parsing and "load default" to methods onCacheConfigwhich are already there asCacheConfig::from_file- For the worker I think ideally creating a
Configwouldn'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::CacheConfigtoCacheand then renamewasmtime_cache::CacheConfigBuildertoCacheConfig. 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 created PR review comment:
While we don't have hard-and-fast conventions in Wasmtime I at least personally prefer builders to take
&mut selfand return&mut Self(likeConfigmethods). Would you be up to changing to that pattern?
alexcrichton created PR review comment:
Mind adding some docs to this method since it'll be public-facing in the
wasmtimecrate API?
alexcrichton created PR review comment:
Mind adding some documentation here? I'm thinking specifically about some error cases for example.
Additionally if you're ok with the
&mut selfsuggestion above, this would change to either&self(ideally) or&mut selfif necessary.
alexcrichton created PR review comment:
If you're ok I'd prefer to leave this not exposed, it's a bit weird to me to go through the rigamarole of creating a config just to say it's disabled. In that sense I think we should consider
CacheConfigBuilderas "always create something with theenabledflag set totrue".
benbrandt commented on PR #10665:
@alexcrichton thanks for the thorough review!
I think all of these changes definitely make sense, and also address some weirdness I felt in implementing this. I can give the changes a try and see how far I get!
benbrandt updated PR #10665.
benbrandt submitted PR review.
benbrandt created PR review comment:
Agreed this indeed felt weird as well, I think we can go with an option on the main config and handle it that way
benbrandt submitted PR review.
benbrandt created PR review comment:
I had a feeling this one might come up, and I figured it was a 50/50 chance I got it right :)
Not a problem
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt updated PR #10665.
benbrandt has marked PR #10665 as ready for review.
benbrandt requested wasmtime-default-reviewers for a review on PR #10665.
benbrandt requested pchickey for a review on PR #10665.
benbrandt updated PR #10665.
benbrandt commented on PR #10665:
@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:
- Previous cache methods on
Confighave been removed in favor of a singlecachemethod that can be set toNoneto disable it, or passed a constructedCache, either from a file or manually configured- I removed
enabledfromCacheConfig(more controversial)The latter felt kind of weird to leave as an option, since now there is either a
Cacheor there is not, and it simplified things to not have to worry if it was enabled or not.However, because of
#[serde(deny_unknown_fields)], this will cause existing config files to not work.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.
However, CLI users would have to fix this themselves.
benbrandt edited a comment on PR #10665:
@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:
- Previous cache methods on
Confighave been removed in favor of a singlecachemethod that can be set toNoneto disable it, or passed a constructedCache, either from a file or manually configured- I removed
enabledfromCacheConfig(more controversial)Other notable changes:
- Introduced a separate
Cachestruct to better separate the config from the actual thing holding the worker- Moved default behavior to serialization time to also remove the awkward workarounds for assuming struct fields are set and not
Noneafter a certain stageThe enabled flag felt kind of weird to leave as an option, since now there is either a
Cacheor there is not, and it simplified things to not have to worry if it was enabled or not.However, because of
#[serde(deny_unknown_fields)], this will cause existing config files to not work.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.
However, CLI users would have to fix this themselves.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!
benbrandt updated PR #10665.
alexcrichton submitted PR review:
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_fieldsand dropenabled = trueas 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.
alexcrichton merged PR #10665.
dev-null-undefined commented on PR #10665:
The documentation seems outdated https://github.com/bytecodealliance/wasmtime/blob/0fabedfece020cab90124768c3dc94b8d95ca4ab/docs/cli-cache.md#setting-enabled
benbrandt commented on PR #10665:
@dev-null-undefined good catch! Made a follow up PR here: https://github.com/bytecodealliance/wasmtime/pull/10859
Last updated: Dec 06 2025 at 07:03 UTC