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

Returning a Vector from GroupElement::to_bytes is slow #5

Open
JayPavlina opened this issue Nov 2, 2019 · 4 comments
Open

Returning a Vector from GroupElement::to_bytes is slow #5

JayPavlina opened this issue Nov 2, 2019 · 4 comments

Comments

@JayPavlina
Copy link

JayPavlina commented Nov 2, 2019

Creating a vector every time GroupElement::to_bytes() is called is slow because it's allocated on the heap. It would be much faster to return a constant sized array. If the two implementations of GroupElement need to return different sized arrays, an alternative solution is to have to_bytes write to a slice that is passed in.

@lovesh
Copy link
Owner

lovesh commented Nov 3, 2019

You are correct. I don't want to break existing usages of to_bytes by dependent codebases but I can certainly add a new method to_bytearray that takes a mutable slice as you mentioned. And overtime, to_bytes can be removed.

@JayPavlina
Copy link
Author

JayPavlina commented Nov 4, 2019

In Rust conventions, naming a function to_ means you are returning something, so I would maybe name the new function write_to_bytes to make it more clear.

Afterwards the new function should be used internally wherever the old one was used.

@lovesh
Copy link
Owner

lovesh commented Nov 9, 2019

Does this sound ok #7

@JayPavlina
Copy link
Author

Yes it looks good

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