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

Fix clippy warnings #500

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Fix clippy warnings #500

wants to merge 3 commits into from

Conversation

i1i1
Copy link
Contributor

@i1i1 i1i1 commented Sep 23, 2022

No description provided.

if let Some(timestamp) = self.timestamp {
self.block_times.push(now.saturating_sub(timestamp));
self.average_block_time = Some(self.block_times.average());
match block.height.cmp(&self.best.height) {
Copy link
Member

Choose a reason for hiding this comment

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

I'm not a fan of this change if think the old code was easier to read.

which clippy lint is this?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@i1i1 i1i1 requested a review from niklasad1 September 26, 2022 09:59
("1Mi", 1 * 1024 * 1024),
("1GiB", 1 * 1024 * 1024 * 1024),
("1Gi", 1 * 1024 * 1024 * 1024),
(" 1 Gi ", 1 * 1024 * 1024 * 1024),
Copy link
Member

Choose a reason for hiding this comment

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

these are just silly, so much more readable before :)

perhaps we could should add a clippy config for style lints like this one.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I'd be up for a clippy config being added to telemetry so that we can keep more of what we like; I'm generally happy with these changes but there isn't much value in adding Default impls and a couple of other nits I have (but I htink nits are allowed since that's what clippy is all about!)

Comment on lines +34 to +43
impl<Id, Details> Default for AssignId<Id, Details>
where
Details: Eq + Hash,
Id: From<usize> + Copy,
usize: From<Id>,
{
fn default() -> Self {
Self::new()
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

I guess #[derive(Default)] didn't work? I'd prefer that if possible :)

Copy link
Member

Choose a reason for hiding this comment

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

BiMap doesn't impl Default

@jsdw
Copy link
Collaborator

jsdw commented Oct 10, 2022

I'm ok with most of these changes, but perhaps we should sit down, make an issue and write a proper clippy config as @niklasad1 suggests so that we can decide what we want to ignore/change in telemetry and then run over and this the warnings there.

@niklasad1 are you up for doing that when you have some time?

@@ -55,13 +55,13 @@ pub enum FromShardWebsocket {
Add {
local_id: ShardNodeId,
ip: std::net::IpAddr,
node: common::node_types::NodeDetails,
node: Box<common::node_types::NodeDetails>,
Copy link
Member

Choose a reason for hiding this comment

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

std::mem::size_of::<NodeDetails>() == 111

I think that is small enough to avoid to Box this one

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, but enum variant is around 369 bytes:

warning: large size difference between variants
  --> telemetry_core/src/aggregator/inner_loop.rs:48:1
   |
48 |   / pub enum FromShardWebsocket {
49 |   |     /// When the socket is opened, it'll send this first
50 |   |     /// so that we have a way to communicate back to it.
51 |   |     Initialize {
...    |
55 | / |     Add {
56 | | |         local_id: ShardNodeId,
57 | | |         ip: std::net::IpAddr,
58 | | |         node: common::node_types::NodeDetails,
59 | | |         genesis_hash: common::node_types::BlockHash,
60 | | |     },
   | |_|_____- the largest variant contains at least 369 bytes
61 |   |     /// Update/pass through details about a node.
62 | / |     Update {
63 | | |         local_id: ShardNodeId,
64 | | |         payload: Box<node_message::Payload>,
65 | | |     },
   | |_|_____- the second-largest variant contains at least 16 bytes
...    |
69 |   |     Disconnected,
70 |   | }
   |   |_^ the entire enum is at least 376 bytes
   |
   = note: `#[warn(clippy::large_enum_variant)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#large_enum_variant
help: consider boxing the large fields to reduce the total size of the enum
   |
58 |         node: Box<common::node_types::NodeDetails>,
   |               ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

genesis_hash: common::node_types::BlockHash,
},
/// Update/pass through details about a node.
Update {
local_id: ShardNodeId,
payload: node_message::Payload,
payload: Box<node_message::Payload>,
Copy link
Member

Choose a reason for hiding this comment

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

std::mem::size_of::<Payload>() == 344, I'm still in favor to avoid to box this but not sure where to cut the threshold without benching it ^^.

Clippy seems to use 200 as default, https://rust-lang.github.io/rust-clippy/master/#large_enum_variant

Copy link
Member

@niklasad1 niklasad1 left a comment

Choose a reason for hiding this comment

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

nice work, my comments are towards the default clippy settings which we could take care of it in another PR as @jsdw said.

@niklasad1
Copy link
Member

@niklasad1 are you up for doing that when you have some time?

Sure, it seems like I'm the grumpy one against the default clippy warnings so sure :)

@jsdw
Copy link
Collaborator

jsdw commented Oct 10, 2022

I'd suggest just starting with this PR if it's useful, adding some clippy rules, adding the CI check too (since this PR doesn't have it) and making a new PR. Then we can close this one since it's conflicting at the mo anyway.

But whatever is easiest!

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.

None yet

3 participants