dfinity / motoko

Simple high-level language for writing Internet Computer canisters
Apache License 2.0
517 stars 97 forks source link

Cheaper memcopy via stable memory? #2564

Closed nomeata closed 3 years ago

nomeata commented 3 years ago

Until the Internet Computer refines the instruction counting, the fastest way to do memcpy is to copy to stable memory and then again from.

Motoko doesn’t use stable memory during normal execution, so we can use it as scratch space.

We should measure how large a memcpy needs to be to make going via stable memory cheaper, and then use that in memcpy_bytes in src/mem.rs. We need to be careful to not use it in pre_upgrade and post_upgrade.

Best put behind a flag so that developers can opt-out so that when instruction counting is refined, they don’t have to wait for a motoko upgrade.

crusso commented 3 years ago

Isn't that cheating?

nomeata commented 3 years ago

It’s optimizing for what our users care about

nomeata commented 3 years ago

Probably not worth doing that, I expect the IC to fix that hole in time (https://github.com/dfinity-lab/dfinity/pull/12103)