Skip to content

chore(store): store.v1LegacyLayout no longer uses fmt.Sprintf() to create DB keys. - #4489

Merged
alesforz merged 17 commits into
mainfrom
alesforz/blockstore-v1LegacyLayout-sprintf
Nov 15, 2024
Merged

alesforz merged 17 commits into
mainfrom
alesforz/blockstore-v1LegacyLayout-sprintf

Conversation

@alesforz

@alesforz alesforz commented Nov 13, 2024 •

Copy link
Copy Markdown
Collaborator

The v1LegacyLayout type of pkg store uses fmt.Sprintf() to create the DB keys.
This PR refactors functions using fmt.Sprintf to improve their speed and memory usage.


PR checklist

  • Tests written/updated
  • Changelog entry added in .changelog (we use unclog to manage our changelog)
  • Updated relevant documentation (docs/ or spec/) and code comments

@alesforz alesforz self-assigned this Nov 13, 2024
@alesforz alesforz changed the title chore(store) store.v1LegacyLayout no longer uses fmt.Sprintf() to create DB keys. chore(store): store.v1LegacyLayout no longer uses fmt.Sprintf() to create DB keys. Nov 13, 2024
@cometbft cometbft deleted a comment from github-actions Bot Nov 13, 2024
Alessandro added 14 commits November 13, 2024 18:22
It now encodes to hex the `hash` it receives as argument as the prev version
did.
After benchmarking, I found that while extracting the helper method reduces
code duplication, it negatively affects performance. This is because `buildKey`
allocates the `key` slice using a calculated expression:
`make([]byte, 0, len(prefix)+20)`.
Since the compiler cannot determine `len(prefix)` at compile time, it likely
allocates extra memory for the slice.

This reverts commit 8fd2f36.
The compiler will recognize the slice's capacity as a compile-time constant and
apply optimizations that avoid unnecessary allocations.
@alesforz alesforz added storage P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably chore labels Nov 14, 2024
@alesforz
alesforz marked this pull request as ready for review November 14, 2024 15:21
@alesforz
alesforz requested a review from a team as a code owner November 14, 2024 15:21
@alesforz
alesforz requested a review from a team November 14, 2024 15:21
@alesforz
alesforz added this pull request to the merge queue Nov 15, 2024
Merged via the queue into main with commit 16b1ed8 Nov 15, 2024
@alesforz
alesforz deleted the alesforz/blockstore-v1LegacyLayout-sprintf branch November 15, 2024 09:45
@alesforz

Copy link
Copy Markdown
Collaborator Author

Note: the changes in this PR are superseded by #4490.

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

Labels

chore P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably storage

Projects

No open projects
Status: Done

Development

Successfully merging this pull request may close these issues.

2 participants