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

Move FFI::DataConverter to Ruby #661

Merged
merged 3 commits into from Jan 22, 2019

Conversation

eregon
Copy link
Collaborator

@eregon eregon commented Jan 7, 2019

  • Include DataConverter in StructByReference in Ruby code to simplify ordering.

See #660 for context.

* Include DataConverter in StructByReference in Ruby code to simplify
  ordering.
@eregon eregon force-pushed the move-data-converter-to-ruby branch from c552400 to 96bf421 Compare January 7, 2019 22:37
@eregon
Copy link
Collaborator Author

eregon commented Jan 7, 2019

This is now ready for review.

@larskanis
Copy link
Member

LGTM

Copy link
Contributor

@headius headius left a comment

Choose a reason for hiding this comment

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

Ruby impl seems to have most of the same behavior as the C code, so I suspect this should be fine.

@eregon
Copy link
Collaborator Author

eregon commented Jan 10, 2019

Can we merge this?

@tduehr Could you review?

I think this doesn't touch performance critical-code, but I'm happy to run some benchmarks if you tell me which ones would be relevant for this.

The behavior seems similar to the DataConverter class in JRuby, except that one has the extra reference_required and reference_required? methods.

@tduehr
Copy link
Member

tduehr commented Jan 10, 2019

There's more to it than just the module itself. I'll take a look at usage today.

I expect this code is used in converting from ruby to C/JAva and back... Any benchmark covering that should be good.

Can you get the benchmark suite working, or at least find the holes? That'd be awesome too...

@headius
Copy link
Contributor

headius commented Jan 10, 2019

@tduehr Even if this is on the hot path it's probably a lateral move changing this code to Ruby. It may even be faster in some cases since the C code (and the Java code, for that matter) does uncached instance variable lookups.

@tduehr
Copy link
Member

tduehr commented Jan 10, 2019

The licensing is all over the place. We'll want to consolidate that at some point.

* The same as errno.rb. DataConverter.c was added by Wayne Meissner.
@eregon
Copy link
Collaborator Author

eregon commented Jan 10, 2019

I added the license header.

@tduehr tduehr merged commit 353d787 into ffi:master Jan 22, 2019
@eregon
Copy link
Collaborator Author

eregon commented Feb 1, 2019

For the record, I checked, and none of the benchmarks, nor the tests ever calls FFI::DataConverter#to_native or FFI::DataConverter#from_native, and DataConverter#native_type is only called during require 'ffi'.

It's easy to adapt bench_chmod.rb to use it by changing :string arguments to :strptr (which is not useful in practice, :strptr is only useful as a return type, but then it overrides from_native which doesn't call in DataConvert anymore), and as expected the performance difference is insignificant.

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.

None yet

4 participants