Skip to content

Sub-Linear memory for BaseLayerIterator #16

@robinhundt

Description

@robinhundt

In 1ba607e we already improved the BaseLayerIter. However, there is an easy improvement we could do to the iteration code to reduce the memory from O(|base_circuit|) to something less than that. Currently, this linear memory cost is due to storing the inputs needed for each gate in a flat vec and calculating this for each gate in constructor. A, hopefully, better way would be to store a mapping of HashMap<GateId, u32> where we only store the inputs needed for gates of which at least one predecessor has already been processed and remove them when they are zero.
The intuition is that a gate for which no predecessor has been processed can't be yielded and once we yield a gate we can not yield it again, thus we don't need to store how many inputs are needed for these gates. Albeit a little more computationally costly, this should significantly reduce the memory cost of iteration objects for large base circuits.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions