celestiaorg / rsmt2d

Go implementation of two dimensional Reed-Solomon merkle tree data availability scheme.
Apache License 2.0
162 stars 79 forks source link

perf: Consider removing deepcopy #311

Open walldiss opened 7 months ago

walldiss commented 7 months ago

The use of deepcopy() in our codebase significantly reduces performance because of the large number of allocations it requires. There is no need for deepcopy() if the caller only wishes to read the data and not modify it. This creates a performance burden for readers to protect the interests of those who may want to modify the data. It would be more efficient to perform deepcopy() on the caller's side when necessary, rather than doing it implicitly all the time. We might want to consider documenting exported methods to indicate that a deepcopy() is needed if the data is to be modified. And remove preemptive deepcopy() from exported methods.

Wondertan commented 7 months ago

Related to https://github.com/celestiaorg/rsmt2d/issues/232