Skip to content

Array optimizations for ERC1155 #3940

@frangio

Description

@frangio

This PR refers to the next-v5.0 branch. In #3876 two potential optimizations were identified.

  1. _asSingletonArray: Throughout the contract we use:
        uint256[] memory ids = _asSingletonArray(id);
        uint256[] memory amounts = _asSingletonArray(amount);

We could combine this into a single function _asSigletonArrays(id, amount) and using assembly we would be able to do a single allocation and possibly avoid a couple of bounds checks.

  1. _unsafeAccess: In places where we loop over arrays of ids and amounts, we don't need to do bounds checking inside the for loop, so we could define a function to skip it.

Given that these are arrays in memory, it's unclear how much of an improvement these optimizations will make, so we have to benchmark to know for sure.

Based on the results of using _unsafeAccess for memory arrays we should consider applying it in other places

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions