Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This change allows anything which uses the new allocator-based APIs to limit memory use in any part of Rune through
rune::alloc::memory::with
:Closures and futures can be limited this way, and if the limit is reached for a given thread an error will be raised (not panic) which is propagated up through regular error handling facilities. Effectively this means that any user of Rune should be able to implement a rigorous memory sandbox that can take untrusted input and stay within defined memory limits.
CC LemmyNet/lemmy#3277
Caveats and missing pieces
The following is a non-exhaustive list of types and operations which are still not covered by the allocator:
[_]::sort
, which uses timsort that might allocate a cache up to half the size of the elements being sorted.Path
/PathBuf
.RelativePath
/RelativePathBuf
.std::fs::read_to_string
.serde_json
using a string buffer. Owned types being passed in are not accounted for until they've been converted to internal types.Rc
andArc
have not been forked. Mainly because their memory overhead is fixed and relative to other collections which store them internally, We might still decide to fork them to ensure that we get full coverage.std
/alloc
types such asString
andVec
which just haven't been ported yet because they're not considered important.All of these can easily be dealt with except serde. It's up to the serialization format to construct owned buffers and this is not something we can control. When this feature is released there will be a warning associated with all serialization modules (currently
json
andtoml
).The other APIs will be copied into
rune_alloc
and given appropriate implementations which uses therune_alloc
allocator API.