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

device: reduce RoutineHandshake allocations #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

AlexanderYastrebov
Copy link

Reduce allocations by eliminating byte reader, hand-rolled decoding and reusing message structs.

Reduce allocations by eliminating byte reader, hand-rolled decoding and
reusing message structs.

Signed-off-by: Alexander Yastrebov <[email protected]>
Comment on lines +121 to +124
func (msg *MessageInitiation) unmarshal(b []byte) error {
if len(b) < MessageInitiationSize {
return errMessageTooShort
}
Copy link
Author

Choose a reason for hiding this comment

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

Maybe name it reset.

Also the size of the packet is checked earlier

case MessageInitiationType:
if len(packet) != MessageInitiationSize {
continue
}
case MessageResponseType:
if len(packet) != MessageResponseSize {
continue
}
case MessageCookieReplyType:
if len(packet) != MessageCookieReplySize {
continue
}

so this check could be removed as well as error result check at the callsite.

@@ -286,17 +290,15 @@ func (device *Device) RoutineHandshake(id int) {

// unmarshal packet

var reply MessageCookieReply
reader := bytes.NewReader(elem.packet)
Copy link
Author

@AlexanderYastrebov AlexanderYastrebov Jan 2, 2025

Choose a reason for hiding this comment

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

Here byte reader can be replaced with https://pkg.go.dev/encoding/binary#Decode added in 1.23 golang/go#60023 (comment)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

1 participant