-
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
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
Conversation
.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)) { |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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 │
└─────────┴───────────┴─────────────┴────────────────────┴──────────┴──────────┘
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see, thanks!
lib/extension/bind.ts
Outdated
return false; | ||
} | ||
|
||
if (e.configuredReportings.some((c) => c.cluster.name === bind.cluster.name) && |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 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: