Subject: Re: [ruby-ffi] Performance help |
From: John Croisant |
Date: 12/31/09 7:11 PM |
To: ruby-ffi@googlegroups.com |
On Thu, Dec 31, 2009 at 1:25 PM, Shawn Anderson <shawn42@gmail.com> wrote:
http://github.com/shawn42/chipmunk-ffi you will need ffi 0.6 and nice-ffi 0.2 and chipmunk built from svn ( http://code.google.com/p/chipmunk-physics/source/checkout ) /ShawnI'm seeing my ffi version of chipmunk bindings are about 10 times slower. Can any experts take a look and tell me if I'm doing something wrong?
I don't see anything that you've done _wrong_, but it can be significantly optimized. The main source of slowness is creating the struct. For something this simple, and which will be created so frequently, using NiceFFI adds more overhead than you want, and doesn't give you much benefit. NiceFFI itself could probably be optimized quite a bit, but I would suggest using a plain FFI::Struct for this anyway. On my system, changing to FFI::Struct reduced the struct creation time by 40%. You will need to take care of memory management for pointers returned by the library, but that's easily accomplished using FFI::AutoPointer. Even with that optimization, creating a struct with FFI is quite a bit slower than creating it in C, which I think should be expected. But maybe other people have some more optimization tips besides "Don't use John's slow library." ;-) - John P.S. I've sent you a pull request that implements the changes I've talked about here.