aptos-core icon indicating copy to clipboard operation
aptos-core copied to clipboard

[move-stdlib] Add vector::move_range native function

Open igor-aptos opened this issue 4 months ago • 2 comments

Description

Memcopy (i.e. ptr::copy_nonoverlapping inside of Vec) is extremely efficient, and using Vec operations that use it directly is significantly faster (orders of magnitude on bigger vectors) than issuing operations in move.

Operations on vector that can be speed-up: insert, remove, append, split_off.

To keep amount of native functions short, instead of having native for each of those, providing one more general native function: vector::move_range, which is enough to support all 4 of the above, in addition to other uses.

Internally, we shortcircuit a few special cases, for faster speed.

How Has This Been Tested?

Full performance evaluation is in the follow-up PR: #14862

Key Areas to Review

Type of Change

  • [x] Performance improvement

Which Components or Systems Does This Change Impact?

  • [x] Move/Aptos Virtual Machine

Checklist

  • [x] I have read and followed the CONTRIBUTING doc
  • [x] I have performed a self-review of my own code
  • [x] I have commented my code, particularly in hard-to-understand areas
  • [x] I identified and added all stakeholders and component owners affected by this change as reviewers
  • [x] I tested both happy and unhappy path of the functionality
  • [ ] I have made corresponding changes to the documentation

igor-aptos avatar Oct 03 '24 22:10 igor-aptos