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

replace memcpy with AbstractMemory#put_bytes() in FFI implementation #43

Closed
flavorjones opened this issue May 11, 2009 · 1 comment
Closed

Comments

@flavorjones
Copy link
Member

From Wayne Meissner:

I noticed in nokogiri, in Document.read_io that you use LibXML.memcpy to transfer data from a ruby string to a native memory buffer.

It'll be much faster to use AbstractMemory#put_bytes(), as the memcpy mapping will triple copy the string data on JRuby.

basically, what happens behind the scene is:

  1. The string data is copied to a temporary native memory buffer
  2. The temp memory is passed as the parameter
  3. memcpy copies the data from the temp memory to the destination memory you specified
  4. The temporary native memory is copied back to the ruby string.

compared to put_bytes:

  1. The string data is copied once from the ruby byte array backing the ruby string into the destination memory address.
  2. There is no step 2.

For large files, this might make a difference.

@flavorjones
Copy link
Member Author

FFI: IO reader callbacks now use AbstractMemory#put_bytes instead of memcpy, per Wayne's advice. along the way, refactored callbacks. closed by 0b87111.

This issue was closed.
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

1 participant