pietern/hiredis-rb — pull request #13 by dbussink (2013-05-10 09:35:32+00:00)
Title: Improve Rubinius support in hiredis

When profiling a Sidekiq app, this showed a few places in hiredis that
could be changed with not affecting MRI in a bad way, but improving
performance on Rubinius.

Because Rubinius has a generational garbage collector, writes to an
array need to go through a write barrier. If a C extension uses
RARRAY_PTR, this works around the barrier. For this, Rubinius has to
setup additional support by scanning the whole array when returning from
a C extension function call. This mechanism is only activated when
RARRAY_PTR is used.

By not using this but by using the normal array accessor functions, this
is prevented. On MRI using these functions or RARRAY_PTR don't make any
significant difference.

For strings Rubinius uses a similar mechanisms if extensions modify a
char* if data is modified directly. To disable this copying back there
is a define that can be used to disable it. Since hiredis-rb doesn't
seem to be modyfing buffers obtained with RSTRING_PTR, I've also enabled
this optimization.

Since for Ruby 2.1, MRI is also working on a generational GC, this can
also potentially be an improved for newer versions of MRI if they choose
to use similar mechanisms for optimizations.

This also marks a few global variables that the gem defines as actual
globals so they don't get accidentally garbage collected.