-
Notifications
You must be signed in to change notification settings - Fork 101
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
feat: support IC low Wasm memory hook #4849
base: master
Are you sure you want to change the base?
Conversation
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.
I guess we could consider allowing the return type to be async*
but the method would need to force the async*
somehow. That would avoid another scheduling hop.
Do we want merge this now or wait for the IC implementation to be fixed?
Co-authored-by: Claudio Russo <claudio@dfinity.org>
I changed it to I think we can merge it as soon as it is ready from our side. The IC fix can come later and would be automatically become effective. |
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.
Added one suggestion, otherwise LGTM!
Co-authored-by: Gabor Greif <gabor@dfinity.org>
Thanks for reviewing! |
Supporting Low Memory Hook in Motoko
The IC allows to implement a low memory hook, which is a warning trigger when main memory is becoming scarce.
For this purpose, a Motoko actor or actor class instance can implement the system function
lowmemory()
. This system function is scheduled when canister's free main memory space has fallen below the defined thresholdwasm_memory_threshold
, that is is part of the canister settings. In Motoko,lowmemory()
implements thecanister_on_low_wasm_memory
hook defined in the IC specification.Reference: dfinity/portal#3761
Example of implementing the low memory hook:
The following properties should be considered when using the low memory hook:
lowmemory
happens with a certain delay, as it is scheduled as a separate asynchronous message that runs after the message in which the threshold was crossed.lowmemory
will only be triggered again when the main memory free space grows above the threshold (e.g. by lowering the threshold or shrinking the main memory through canister reinstallation) and then again falls below the threshold.lowmemory
are ignored. They only revert the changes done inlowmemory
.async*
return type, thelowmemory
function may send further messages andawait
results.