Replaces MemorySizer and CompileConfig with RuntimeConfig (#815)
We formerly introduced `MemorySizer` as a way to control capacity independently of size. This was the first and only feature in `CompileConfig`. While possibly used privately, `MemorySizer` has never been used in public GitHub code. These APIs interfere with how we do caching of compiled modules. Notably, they can change the min or max defined in wasm, which invalidates some constants. This has also had a bad experience, forcing everyone to boilerplate`wazero.NewCompileConfig()` despite that API never being used in open source. This addresses the use cases in a different way, by moving configuration to `RuntimeConfig` instead. This allows us to remove `MemorySizer` and `CompileConfig`, and the problems with them, yet still retaining functionality in case someone uses it. * `RuntimeConfig.WithMemoryLimitPages(uint32)`: Prevents memory from growing to 4GB (spec limit) per instance. * This works regardless of whether the wasm encodes max or not. If there is no max, it becomes effectively this value. * `RuntimeConfig.WithMemoryCapacityFromMax(bool)`: Prevents reallocations (when growing). * Wasm that never sets max will grow from min to the limit above. Note: Those who want to change their wasm (ex insert a max where there was none), have to do that externally, ex via compiler settings or post-build transformations such as [wabin](https://github.com/tetratelabs/wabin) Signed-off-by: Adrian Cole <adrian@tetrate.io>
This commit is contained in:
15
api/wasm.go
15
api/wasm.go
@@ -486,18 +486,3 @@ func EncodeF64(input float64) uint64 {
|
||||
func DecodeF64(input uint64) float64 {
|
||||
return math.Float64frombits(input)
|
||||
}
|
||||
|
||||
// MemorySizer applies during compilation after a module has been decoded from wasm, but before it is instantiated.
|
||||
// This determines the amount of memory pages (65536 bytes per page) to use when a memory is instantiated as a []byte.
|
||||
//
|
||||
// Ex. Here's how to set the capacity to max instead of min, when set:
|
||||
//
|
||||
// capIsMax := func(minPages uint32, maxPages *uint32) (min, capacity, max uint32) {
|
||||
// if maxPages != nil {
|
||||
// return minPages, *maxPages, *maxPages
|
||||
// }
|
||||
// return minPages, minPages, 65536
|
||||
// }
|
||||
//
|
||||
// See https://www.w3.org/TR/2019/REC-wasm-core-1-20191205/#grow-mem
|
||||
type MemorySizer func(minPages uint32, maxPages *uint32) (min, capacity, max uint32)
|
||||
|
||||
Reference in New Issue
Block a user