-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
fix: serializing transactions; sort that takes less time and memory #25642
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -395,13 +395,16 @@ export class Transaction { | |
|
||
// Sort. Prioritizing first by signer, then by writable | ||
uniqueMetas.sort(function (x, y) { | ||
const pubkeySorting = x.pubkey | ||
.toBase58() | ||
.localeCompare(y.pubkey.toBase58()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Another string created here. |
||
const checkSigner = x.isSigner === y.isSigner ? 0 : x.isSigner ? -1 : 1; | ||
const checkWritable = | ||
x.isWritable === y.isWritable ? pubkeySorting : x.isWritable ? -1 : 1; | ||
Comment on lines
-401
to
-403
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The CPU and memory that we consumed to produce base58 strings gets thrown out here if the signedness or writability of the accounts differ. |
||
return checkSigner || checkWritable; | ||
if (x.isSigner !== y.isSigner) { | ||
// Signers always come before non-signers | ||
return x.isSigner ? -1 : 1; | ||
} | ||
if (x.isWritable !== y.isWritable) { | ||
// Writable accounts always come before read-only accounts | ||
return x.isWritable ? -1 : 1; | ||
} | ||
// Otherwise, sort by pubkey. | ||
return x.pubkey._bn.cmp(y.pubkey._bn); | ||
}); | ||
|
||
// Move fee payer to the front | ||
|
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.
One string created here.