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

Chore: Use exp/slices and exp/maps to simplify some code #5479

Merged
merged 13 commits into from Jun 22, 2023

Conversation

jannotti
Copy link
Contributor

The intent is to only make changes where the result is clearer, and to catch enough cases that the next time someone does something similar, they will have seen the new, clearer way to write the thing they intend.

@jannotti jannotti self-assigned this Jun 18, 2023
r := make([]io.Closer, len(closers))
copy(r, closers)
return &multiCloser{r}
return &multiCloser{slices.Clone(closers)}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not even sure this needs the clone. When called as varargs, the slice is surely unshared.

@jannotti jannotti force-pushed the generic-stuff branch 3 times, most recently from b874496 to 592d035 Compare June 18, 2023 16:48
@codecov
Copy link

codecov bot commented Jun 18, 2023

Codecov Report

Merging #5479 (c4244a0) into master (f5ad6a5) will decrease coverage by 0.10%.
The diff coverage is 71.15%.

@@            Coverage Diff             @@
##           master    #5479      +/-   ##
==========================================
- Coverage   55.71%   55.62%   -0.10%     
==========================================
  Files         446      446              
  Lines       63292    63153     -139     
==========================================
- Hits        35265    35130     -135     
- Misses      25649    25653       +4     
+ Partials     2378     2370       -8     
Impacted Files Coverage Δ
agreement/autopsy.go 0.00% <0.00%> (ø)
cmd/goal/account.go 13.76% <0.00%> (+0.07%) ⬆️
cmd/tealdbg/local.go 73.88% <0.00%> (+0.23%) ⬆️
daemon/algod/api/server/v2/utils.go 10.46% <0.00%> (+0.04%) ⬆️
data/basics/userBalance.go 30.40% <0.00%> (+0.47%) ⬆️
data/transactions/application.go 63.15% <0.00%> (+1.61%) ⬆️
data/transactions/transaction.go 43.10% <0.00%> (+0.37%) ⬆️
ledger/acctupdates.go 70.46% <ø> (-1.37%) ⬇️
ledger/ledger.go 69.82% <ø> (-0.61%) ⬇️
data/basics/teal.go 21.59% <50.00%> (-5.15%) ⬇️
... and 14 more

... and 18 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

Comment on lines -574 to -576
//
// known artefact of cloning AppLocalState even with empty update, nil map vs empty map
saved.AppLocalStates = map[basics.AppIndex]basics.AppLocalState{}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This appeared to be testing an artifact of the mock, not of a real ledger. The artifact is gone now, because maps.Clone maintains nil.

@jannotti jannotti marked this pull request as ready for review June 19, 2023 18:53
}
}
return true
return maps.Equal(sd, o)
Copy link
Contributor Author

@jannotti jannotti Jun 20, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment goes into a lot of detail about the nil checking choice, but that is exactly the same choice that maps.Equal made. Unit tests already exist to confirm.

crypto/merkletrie/cache.go Show resolved Hide resolved
crypto/merkletrie/committer_test.go Show resolved Hide resolved
data/transactions/transaction.go Outdated Show resolved Hide resolved
ledger/acctupdates.go Show resolved Hide resolved
ledger/apply/mockBalances_test.go Outdated Show resolved Hide resolved
ledger/ledgercore/statedelta.go Outdated Show resolved Hide resolved
The intent is to only make changes where the result is clearer, and to
catch enough cases that the next time someone does something similar,
they will have seen the new, clearer way to write the thing they intend.
NOTE(rsc): This function does NOT call the runtime cmpstring function,
because we do not want to provide any performance justification for
using strings.Compare. Basically no one should use strings.Compare.
Need to do a little gitting around for the memory optimzation reversion.
ahangsu
ahangsu previously approved these changes Jun 22, 2023
Copy link
Contributor

@ahangsu ahangsu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

seems fine to me, based on the assumption that slice.Clone has similar perf to copy

ledger/apply/application_test.go Outdated Show resolved Hide resolved
@jasonpaulos
Copy link
Member

Happy to approve once the merge conflict is fixed

@jannotti jannotti merged commit 91185ae into algorand:master Jun 22, 2023
18 checks passed
// Fetch up to maxResults - len(res) + len(deletedCreatables) from the database,
// so we have enough extras in case creatables were deleted
numToFetch := maxResults - uint64(len(res)) + uint64(len(deletedCreatables))
dbResults, dbRound, err := au.accountsq.ListCreatables(maxCreatableIdx, numToFetch, ctype)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

forgot to remove func (qs *accountsDbQueries) ListCreatables in sql.go and listCreatablesStmt there as well

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks.
#5495

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants