-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
feat: enhance code performance #211
feat: enhance code performance #211
Conversation
src/ledger-keyring.ts
Outdated
} | ||
}); | ||
// fix a edge case when accounts itself has duplicate address |
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 looks to me like this part is actually a fix unrelated to the performance improvement - does it warrant breaking out and a test-case? Also: Do we know that this is always fine?
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 looks to me like this part is actually a fix unrelated to the performance improvement - does it warrant breaking out and a test-case? Also: Do we know that this is always fine?
actually i find that is no necessary, or it will not cause any issue if any edge case happen
e.g
accounts = [acc1, acc1, acc2] , accountDetails = {acc2}
if we take a dry run on the Prev code
- filter accounts where those not in accountDetails, accounts become [acc1, acc1]
- acc1 not in accountDetails, acc1 add to accountDetails
- acc1 not in accountDetails, acc1 add to accountDetails , but the content will be same
- at the end result will become accountDetails = {acc2, acc1}
if we take a dry run on the Updated code
- acc2 in set, skip
- acc1 not in set, acc1 add to accountDetails , add to set
- acc1 in set, skip
- at the end result will become accountDetails = {acc2, acc1}
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!
@legobeat can you merge for me, i dont have the permission |
the PR is to enhance the code performance by not doing N square time complexity loop, instead using
set
data structure to improve to O(N) time complexitye.g:
deserialize
method, when execute filtering, it compare if the account address in accountDetails by usingObject.keys(this.accountDetails).includes(XXX)
, which is a O(n*n) time complexity, and Object.keys will create extra memory for every filter loopmigrateAccountDetails
methodremoveAccount
method, it is using a redundant loop to search where the address is exist or not