Skip to content
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

Merged
merged 5 commits into from
Jul 19, 2024
Merged

Tmpnet deferrals #429

merged 5 commits into from
Jul 19, 2024

Conversation

feuGeneA
Copy link
Contributor

Why this should be merged

This PR addresses some comments from the tmpnet PR that were deferred.

@feuGeneA feuGeneA marked this pull request as ready for review July 18, 2024 17:00
@feuGeneA feuGeneA requested a review from a team as a code owner July 18, 2024 17:00
iansuvak
iansuvak previously approved these changes Jul 18, 2024
return []interfaces.SubnetTestInfo{
*n.subnetsInfo[n.tmpnet.GetSubnet("A").SubnetID],
*n.subnetsInfo[n.tmpnet.GetSubnet("B").SubnetID],
subnetsInfo := make([]interfaces.SubnetTestInfo, 0)
Copy link
Collaborator

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 use append 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.

Copy link
Contributor

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.

https://blog.lu4p.xyz/posts/slices/

Copy link
Contributor

@cam-schultz cam-schultz left a 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.

cam-schultz
cam-schultz previously approved these changes Jul 19, 2024
@feuGeneA feuGeneA requested review from cam-schultz and iansuvak July 19, 2024 14:19
geoff-vball
geoff-vball previously approved these changes Jul 19, 2024
Signed-off-by: F. Eugene Aumson <feuGeneA@users.noreply.github.com>
@feuGeneA feuGeneA merged commit c6c6117 into main Jul 19, 2024
14 checks passed
@feuGeneA feuGeneA deleted the tmpnet-deferrals branch July 26, 2024 15:53
0xchainlover pushed a commit to avalabsorg/teleporter that referenced this pull request Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants