-
Notifications
You must be signed in to change notification settings - Fork 28
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Tmpnet deferrals #429
Tmpnet deferrals #429
Conversation
addresses review comment #401 (comment)
addresses review comment #401 (comment)
addresses review comment #401 (comment)
tests/local/network.go
Outdated
return []interfaces.SubnetTestInfo{ | ||
*n.subnetsInfo[n.tmpnet.GetSubnet("A").SubnetID], | ||
*n.subnetsInfo[n.tmpnet.GetSubnet("B").SubnetID], | ||
subnetsInfo := make([]interfaces.SubnetTestInfo, 0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Performance doesn't matter much here, but when populating a new slice like this it is generally best to either:
make
the slice an initial size of 0 but an initial capacity large enough for all the entries to be added, and useappend
to add the elements to it (which will not require any additional allocs)make
the slice with an initial size of the length of elements to be added, and the assign directly to the index within the for loop.
As is, it append
could need to alloc a new array and copy all of the contents of the slice there on each iteration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't actually allocate a new array on every iteration. Slices have an underlying capacity. If you append to a full slice, golang will allocate many extra slots, which you may or may not end up using. This gives an amortized runtime cost of O(1), but it's still good practice to allocate a slice of exactly the length you need if it is known.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM once Michael's comment is addressed.
addresses review comment #429 (comment)
Signed-off-by: F. Eugene Aumson <feuGeneA@users.noreply.github.com>
4afe45b
addresses review comment ava-labs/icm-contracts#429 (comment)
Why this should be merged
This PR addresses some comments from the tmpnet PR that were deferred.