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

Bind code optimization/formatting #23110

Merged
merged 3 commits into from
Jun 23, 2024
Merged

Bind code optimization/formatting #23110

merged 3 commits into from
Jun 23, 2024

Conversation

Nerivec
Copy link
Collaborator

@Nerivec Nerivec commented Jun 20, 2024

@Koenkk make sure to triple-check those refactored chained function calls. Tests seem a little light, and some of the logic has lots of depths, easy for coverage (or the dev 😅) to get fooled.
Also, if you see an easy way to fix the coverage, looks like it wasn't detected before.

Also:

  • Fix const casing and some typing in previous cleanup PRs.

.reduce((a, v) => a.concat(v)).filter((b) => b.target === data.group.zh);
const bindsToGroup: zh.Bind[] = [];

for (const device of this.zigbee.devices(false)) {
Copy link
Owner

Choose a reason for hiding this comment

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

What's the benefit of writing it in for loops over the old code?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

It removes a lot of looping. Chained calls make it too easy to forget the depth of the looping 😅

┌─────────┬───────────┬─────────────┬────────────────────┬──────────┬──────────┐
│ (index) │ Task Name │   ops/sec   │ Average Time (ns)  │  Margin  │ Samples  │
├─────────┼───────────┼─────────────┼────────────────────┼──────────┼──────────┤
│    0    │   'Old'   │  '417,144'  │ 2397.2496359703237 │ '±0.36%' │ 2085724  │
│    1    │   'New'   │ '3,984,551' │ 250.96924324733993 │ '±0.23%' │ 19922760 │
└─────────┴───────────┴─────────────┴────────────────────┴──────────┴──────────┘

Copy link
Owner

Choose a reason for hiding this comment

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

I see, thanks!

return false;
}

if (e.configuredReportings.some((c) => c.cluster.name === bind.cluster.name) &&
Copy link
Owner

Choose a reason for hiding this comment

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

Same here, in my opinion this is now harder to read, the variable names of the old code gave some clue what is happening here.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Re-introduced variable names while still keeping the short-circuiting to avoid unnecessary looping on earlier check fail.

@Koenkk Koenkk merged commit 3d772b5 into Koenkk:dev Jun 23, 2024
11 checks passed
@Nerivec Nerivec deleted the bind-cleanup branch June 23, 2024 11:26
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

2 participants