You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
While studying this code I noticed something that fillerRow is as long as ds.width+extendedWidth while fillerExtendedRow is as long as extendedWidth we could take advantage of loop reuse to build both fillerExtendedRow and fillerRow we can simply build them in the same loop and add a guard against the shorter length of extendedWidth
diff --git a/datasquare.go b/datasquare.go
index 0c16f59..5af113b 100644
--- a/datasquare.go+++ b/datasquare.go@@ -80,12 +80,12 @@ func (ds *dataSquare) extendSquare(extendedWidth uint, fillerChunk []byte) error
newSquareRow := make([][][]byte, newWidth)
fillerExtendedRow := make([][]byte, extendedWidth)
- for i := uint(0); i < extendedWidth; i++ {- fillerExtendedRow[i] = fillerChunk- }-
fillerRow := make([][]byte, newWidth)
for i := uint(0); i < newWidth; i++ {
+ if i < extendedWidth {+ fillerExtendedRow[i] = fillerChunk+ }
fillerRow[i] = fillerChunk
}
Agreed and it seem like the optimization you propose still works as expected.
The performance penalty comes at the cost of (in my subjective opinion) slightly less code readability so I think we should only implement this optimization if we need to.
I'm also puzzled by the few instances where benchmarking shows this optimization results in a positive delta. I.e:
While studying this code I noticed something that fillerRow is as long as
ds.width+extendedWidth
while fillerExtendedRow is as long asextendedWidth
we could take advantage of loop reuse to build both fillerExtendedRow and fillerRow we can simply build them in the same loop and add a guard against the shorter length ofextendedWidth
which produces interesting results
/cc @elias-orijtech @liamsi @rootulp @musalbas @staheri14
The text was updated successfully, but these errors were encountered: