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

Manual byte-by-byte copy instead of binary.LittleEndian func #333

Closed
diamondo25 opened this issue Sep 7, 2017 · 14 comments
Closed

Manual byte-by-byte copy instead of binary.LittleEndian func #333

diamondo25 opened this issue Sep 7, 2017 · 14 comments

Comments

@diamondo25
Copy link

I was wondering why sfixed32 and sfixed64 are not using the binary.LittleEndian; the ASM output is optimized a lot.

@awalterschulze
Copy link
Member

awalterschulze commented Sep 7, 2017 via email

@awalterschulze
Copy link
Member

It seems that binary.LittleEndian does an early bounds check and that is what optimizes the asm output
https://golang.org/src/encoding/binary/binary.go?s=1176:1371#L82
Is that what you were talking about?
The rest of the code looks the same and the tests work when I replace the implementation.

But I think it this is the case then we can use the same trick in more places.

I can figure it out, but its easier if you tell me, how did you discover the optimized asm output?
Because then I can try to find more places that can be optimized.

@diamondo25
Copy link
Author

diamondo25 commented Sep 9, 2017 via email

@awalterschulze
Copy link
Member

awalterschulze commented Sep 9, 2017

Ok I am going to assume you are working on this :) It is much appreciated.

It would be nice if we can also compare the binary.LittleEndian with the unsafe version:

*(*int64)(unsafe.Pointer(&dAtA[i])) = v

Because then we can hopefully remove the need for the unsafe marshaler.

@diamondo25
Copy link
Author

diamondo25 commented Sep 9, 2017 via email

@awalterschulze
Copy link
Member

Yes I agree. I would really like to remove the use of unsafe.

@awalterschulze
Copy link
Member

Please let me know if you don't have the time to do this.
I would prefer to get another contributor and I actually very busy, but if you don't have time, I think this change is important enough that I will spend time on it.

@awalterschulze
Copy link
Member

hello @diamondo25 ?

@diamondo25
Copy link
Author

diamondo25 commented Oct 3, 2017 via email

@awalterschulze
Copy link
Member

No problem, just checking. Then I'll take over :)

@diamondo25
Copy link
Author

#339

@awalterschulze
Copy link
Member

I started with an intial comparison
https://github.com/awalterschulze/gorangecheck

The range check hint seems to require a constant.
Unsafe is still a little faster than the range checking hint, but by very little.
I think it might be time to remove unsafe and start using math and constant range check hints where we can :)

@awalterschulze
Copy link
Member

I think its done
#343

@awalterschulze
Copy link
Member

done

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

No branches or pull requests

2 participants