Question

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.

Was it helpful?

Solution

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 git wrapper, and speed was issue that led them to implement git in 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 calls die() on pretty much any error.

The demand for a proper git library led to the development of libgit2. It even comes with Ruby bindings! Since you want to integrate git functionality with your application, you should check it out.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top