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

imp: avoid unnecessary clones and validations when creating ClientId #1015

Merged
merged 8 commits into from
Dec 21, 2023

Conversation

mina86
Copy link
Contributor

@mina86 mina86 commented Dec 21, 2023

Introduce ClientType::get_client_id method which constructs a new
ClientId but forgoes client type verification. The client type has
already been verified at creation and the verification guarantees that
formatted ClientId will also be valid.

Furthermore, rewrite ClientId::new so that it doesn’t take ownership
of the client type and doesn’t allocated temporary strings.
Furthermore, since ClinetType::get_client_id is now a thing, change
the client type argument to be &str so that constructing ids from
string client type is easier.

Closes: #1014


PR author checklist:

  • Added changelog entry, using unclog.
  • Added tests.
  • Linked to GitHub issue.
  • Updated code comments and documentation (e.g., docs/).
  • Tagged one reviewer who will be the one responsible for shepherding this PR.

Reviewer checklist:

  • Reviewed Files changed in the GitHub PR explorer.
  • Manually tested (in case integration/unit/mock tests are absent).

Introduce ClientType::get_client_id method which constructs a new
ClientId but forgoes client type verification.  The client type has
already been verified at creation and the verification guarantees that
formatted ClientId will also be valid.

Furthermore, rewrite ClientId::new so that it doesn’t take ownership
of the client type and doesn’t allocated temporary strings.
Furthermore, since ClinetType::get_client_id is now a thing, change
the client type argument to be `&str` so that constructing ids from
string client type is easier.
Copy link

codecov bot commented Dec 21, 2023

Codecov Report

Attention: 4 lines in your changes are missing coverage. Please review.

Comparison is base (7ff743b) 70.90% compared to head (69c013f) 70.93%.

Files Patch % Lines
...core/ics24-host/types/src/identifiers/client_id.rs 66.66% 4 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main    #1015      +/-   ##
==========================================
+ Coverage   70.90%   70.93%   +0.03%     
==========================================
  Files         178      178              
  Lines       17995    17983      -12     
==========================================
- Hits        12759    12756       -3     
+ Misses       5236     5227       -9     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

Nice optimization. Awesome 👌🏻
Just a few comments, we can merge then.

mina86 and others added 5 commits December 21, 2023 23:36
…ew.md

Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Copy link
Member

@Farhad-Shabani Farhad-Shabani left a comment

Choose a reason for hiding this comment

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

🙏

@Farhad-Shabani Farhad-Shabani added this to the v0.49.0 milestone Dec 21, 2023
@Farhad-Shabani Farhad-Shabani merged commit 9c29cb4 into cosmos:main Dec 21, 2023
13 checks passed
@mina86 mina86 deleted the b branch December 21, 2023 22:50
Farhad-Shabani added a commit that referenced this pull request Sep 9, 2024
…1015)

* imp: avoid unnecessary clones and validations when creating ClientId

Introduce ClientType::get_client_id method which constructs a new
ClientId but forgoes client type verification.  The client type has
already been verified at creation and the verification guarantees that
formatted ClientId will also be valid.

Furthermore, rewrite ClientId::new so that it doesn’t take ownership
of the client type and doesn’t allocated temporary strings.
Furthermore, since ClinetType::get_client_id is now a thing, change
the client type argument to be `&str` so that constructing ids from
string client type is easier.

* wip

* clippy

* Update .changelog/unreleased/breaking-changes/1014-better-client-id-new.md

Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Signed-off-by: Michal Nazarewicz <mina86@mina86.com>

* build_client_id

* drop variant

* Update 1014-better-client-id-new.md

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>

---------

Signed-off-by: Michal Nazarewicz <mina86@mina86.com>
Co-authored-by: Farhad Shabani <Farhad.Shabani@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

Avoid unnecessary validation and allocations in ClientId::new
2 participants