I agree with the people who think the questions surrounding performance
are lacking. If you provide no meaningful context the best advice we
can offer is profile your application, find the bottlenecks, and try to
improve them. These are basic programming skills which do not require
any knowledge of C whatsoever. There are plenty of tools and tutorials
one click away from a Google search to help. Heck, you'll even find
help on this list if you ask the right question. Here's another general
pointer for anyone looking for such things: check out Stephen Kaes'
blog. He has some interesting posts on how to speed up Rails apps (I
believe the OP stated the project was a Rails app). Outside of all the
things mentioned above, there is not much more general advice to be
given out on this subject.

If you are already proficient with C, then there are additional
advanced tweaks you could make to improve the performance of your code.
But no one on this list can answer that question, because we have no
idea what your problem domain is, how fast your current app is, or what
your target performance metric is. Which brings me to my last point.

If you want more specific advice, please provide more specific context.
If you find people on this list short of patience with these questions,
it's because they take this as *understood*. If you show us a few lines
of code and say, "this seems really slow to me" you may get some
helpful pointers. Someone may write a faster version for you or offer
general advice like: use an array as a buffer or some such thing. In
the end, you will not be able to fix your performance problem without
measurement on *your* platform.

Most of this has nothing to do with the OP's initial question. He wants
to shave some time off a particular algorithm. My best advice to him:
post some code or else at least describe the general procedure ex: "I
create a jagged array, loop through it, sort it, flatten it, eliminate
the dupes" or whatever. It's quite difficult for any of us to be
helpful in the absence of data. Other than that, let me wish you the
best of luck with your project.