Skip to content

🛤 Bulk memory operations #1114

Closed
Closed

Description

@binji

This is a tracking issue for a post-MVP feature
It will be updated as the issue progresses.

Topic Bulk memory operations
Champion Ben Smith @binji
Status in progress
Phase Feature proposal
Linked issues #236 #977 #1057
Linked repositories bulk-memory-operations

Details

Copying and clearing large memory regions is very common, and making these
operations fast is architecture dependent. Although this can be done in the MVP
via i32.load and i32.store, this requires more bytes of code and forces VMs
to recognize the loops as well. The following operators can be added to improve
performance:

  • move_memory: Copy data from a source memory region to destination region;
    these regions may overlap: the copy is performed as if the source region was
    first copied to a temporary buffer, then the temporary buffer is copied to
    the destination region
  • set_memory: Set all bytes in a memory region to a given byte

We expect that WebAssembly producers will use these operations when the region
size is known to be large, and will use loads/stores otherwise.

Activity

  1. binji commented on Jul 24, 2017

    @binji
    MemberAuthor
  2. changed the title [-]Bulk memory operations[/-] [+]🛤 Bulk memory operations[/+] on Jul 25, 2017
  3. locked and limited conversation to collaborators on Jul 25, 2017
  4. self-assigned this
    on Jul 27, 2017
  5. lars-t-hansen commented on Aug 7, 2017

    @lars-t-hansen
    Contributor

    I'm a little concerned about how the temp buffer interacts with shared memory and observability of reads and writes since, in practice, we'll want to avoid using such a buffer. Specifically, the agent that performs the copying creates an order s.t. all reads from the source and writes to the temp buffer are ordered before all reads from the temp buffer and writes to the destination. Another agent can be writing to the source and reading from the target to see what happens; almost certainly that agent can observe that the ordering implied by the temp buffer is violated.

    Now, that violation might be allowed by the memory model anyway, since move_memory performs all racy reads and writes. (What memory model? I hear you ask :-) So no big deal, maybe.

    Still, I have this nagging thought that we should perhaps spec move_memory by cases (not overlapping; overlapping with src <= target; overlapping with src > target) to avoid unnecessary confusion. Also it would clarify the performance aspect of the instruction somewhat better, since the redundant copy makes it seem more expensive than it is.

  6. binji commented on Aug 7, 2017

    @binji
    MemberAuthor

    I wrote up a quick gist w/ some spec text here: https://gist.github.com/binji/acc43b94c0a747e51dfafa1b5b099c9a

    This still uses a temp buffer, but I think it makes it clearer that it is just a spec implementation detail. Probably could add a note to that effect as well.

  7. binji commented on Oct 16, 2018

    @binji
    MemberAuthor
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions