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

perf: a little optimization for Transactions() methods #527

Conversation

igorcrevar
Copy link
Contributor

Changes inside Transactions() []Transaction methods:

  • in advance allocate memory for returning slice of Transactions (size of slice is known)
  • use map to mark invalid transactions replacing the previous loop through an invalid slice.

Additionally, a cachedTransactions slice can be introduced within each struct, allowing for immediate return from the method when the slice is not nil, if you ok with that?

@igorcrevar igorcrevar force-pushed the feature/transactions_methods_optimisation branch from eb9d9e2 to 068c220 Compare March 11, 2024 16:17
@igorcrevar igorcrevar changed the title a little optimization for Transactions() []Transaction methods perf: a little optimization for Transactions() methods Mar 11, 2024
Copy link
Contributor

@agaffney agaffney left a comment

Choose a reason for hiding this comment

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

This looks great, and I even learned a few things (such as t.Run()). Thanks for your contribution!

@agaffney
Copy link
Contributor

@igorcrevar it's probably not that helpful to cache the transactions when it's only avoiding building a small array of known size

@agaffney agaffney merged commit cb6c052 into blinklabs-io:main Mar 11, 2024
6 checks passed
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.

2 participants