Skip to content

chore(state): v1LegacyLayout keys no longer use fmt.Sprintf(). - #4484

Merged
alesforz merged 4 commits into
mainfrom
alesforz/v1keylayout-sprintf
Nov 13, 2024
Merged

alesforz merged 4 commits into
mainfrom
alesforz/v1keylayout-sprintf

Conversation

@alesforz

@alesforz alesforz commented Nov 13, 2024 •

Copy link
Copy Markdown
Collaborator

The v1LegacyLayout type uses fmt.Sprintf() to create the DB keys. This PR substitutes fmt.Sprintf with string concatenation, which is 3-4 times faster for such a simple string.

In general, we shouldn't use fmt.Sprintf() to concatenate strings, because it's inefficient.
Exceptions could be constructing error messages (but we should use fmt.Errorf() for that) or tests.


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 added the chore label Nov 13, 2024
@alesforz alesforz added the P:tech-debt Priority: Technical debt that needs to be paid off to enable us to move faster, reliably label Nov 13, 2024
@alesforz
alesforz marked this pull request as ready for review November 13, 2024 14:33
@alesforz
alesforz requested a review from a team as a code owner November 13, 2024 14:33
@alesforz
alesforz requested a review from a team November 13, 2024 14:33

@melekes melekes left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

👍

@jmalicevic

Copy link
Copy Markdown
Collaborator

Maybe you can do the same for the blockStore? https://github.com/cometbft/cometbft/blob/alesforz/v1keylayout-sprintf/store/db_key_layout.go

@alesforz

alesforz commented Nov 13, 2024 •

Copy link
Copy Markdown
Collaborator Author

Maybe you can do the same for the blockStore? https://github.com/cometbft/cometbft/blob/alesforz/v1keylayout-sprintf/store/db_key_layout.go

Will do it in a separate PR 👍

@alesforz
alesforz added this pull request to the merge queue Nov 13, 2024
Merged via the queue into main with commit 326c330 Nov 13, 2024
@alesforz
alesforz deleted the alesforz/v1keylayout-sprintf branch November 13, 2024 16:38
@alesforz

Copy link
Copy Markdown
Collaborator Author

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

mergify Bot added a commit that referenced this pull request Nov 20, 2024
This PR refactors the `v1LegacyLayout` key creation to improve its speed
and reduce its memory usage.
Follow up to #4484.

---

#### PR checklist

- [x] Tests written/updated
- [x] Changelog entry added in `.changelog` (we use
[unclog](https://github.com/informalsystems/unclog) to manage our
changelog)
- [x] Updated relevant documentation (`docs/` or `spec/`) and code
comments

---------

Co-authored-by: mergify[bot] <37929162+mergify[bot]@users.noreply.github.com>
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.

3 participants