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

Improve TypedArray::to_vec performance by not zero-initializing buffer #2650

Merged
merged 1 commit into from
Aug 9, 2021

Conversation

adrian17
Copy link
Contributor

@adrian17 adrian17 commented Aug 8, 2021

You can see the rationale and results in #2639 .

Changes:

  • changed raw_copy_to to take pointers instead of slices (as slices require data to be pre-initialized)
  • made it unsafe, as even though technically we don't use any unsafe APIs, invalid use can modify random memory
  • made it pub (this part is optional, let me know if you don't want this PR to extend public API)
  • use it in to_vec(). The general pattern of with_capacity->modify through pointer->set_len is similar to the official example in https://doc.rust-lang.org/std/vec/struct.Vec.html#method.set_len , and looks sound in general. Still, this does add a significant amount of unsafe uses.

@alexcrichton
Copy link
Contributor

Seems reasonable to me, thanks!

@alexcrichton alexcrichton merged commit 41c22e6 into rustwasm:master Aug 9, 2021
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.

2 participants