What are the major differences between the execution of Ruby C bindings vs. Ruby wrapper for system calls?
To my question into context, I am looking into incorporating Git version control functionality heavily into a Ruby on Rails application. In approaching this task I do not understand the how to think about the execution pipeline of a Ruby program which incorporates a library implemented with Ruby C bindings such as yajl-ruby vs. a Ruby wrapper for system calls such as the git Ruby Gem.
Bindings interface directly with the library’s API, while wrappers use system calls to invoke the end-user application from the command line.
Wrappers are similar to UNIX pipes – programs have no knowledge about each other’s internals and communicate through a textual interface. Loose coupling comes with a price, though. System calls are expensive operations and will dramatically slow down your application.
This is why bindings are great. Since they use the library’s programming interface, the overhead is significantly reduced. GitHub had its own
gitwrapper, and speed was issue that led them to implementgitin Ruby.They did it themselves because it is kind of hard to make bindings for
git. It wasn’t designed to be used as a library. It’s really awkward to call its functions directly since it callsdie()on pretty much any error.The demand for a proper
gitlibrary led to the development oflibgit2. It even comes with Ruby bindings! Since you want to integrategitfunctionality with your application, you should check it out.