I actually don't know. It depends on what users want. I am okay
with the optional dependency, but if people really hate RMagick (and I
know many do), it'd be better as its own gem.
What does everyone think? I'm a bit hesitant to include this in core
because I don't plan to test / maintain it because I have no desire to
install RMagick.
-greg
And btw, thanks for this. I'm sure it's going to make some of our
users pretty happy.
-greg
I'm happy to help. :) Thanks for creating Prawn for you and all
contributors in the first place.
Greetings,
Wojciech
I'm a big fan of the KISS principle. :)
Profiling of my test script showed that it was spending most of its
time in PNG#unfilter_image_data. I've decided to speed up this method
first and see if the performance I get would be enough. Optimizing
Ruby code gave only minor speedups, so I've looked at RMagick.
There are many more possibilities for using RMagick in Prawn, but the
benefits may not be worth the hassle.
> A roughly benchmark:
>
> Without prawn-fast-png:
>
> real 0m0.945s
> user 0m0.864s
> sys 0m0.080s
>
> With prawn-fast-png:
>
> real 0m0.333s
> user 0m0.288s
> sys 0m0.044s
>
> Looks nice....
Your benchmark shows some speed up, but I wouldn't have messed with
RMagick for such a small improvement. You either have a speedy machine
there or you are embedding a small image. I needed to insert
~1000x4000 sized PNGs with alpha channel and that was simply not
possible with clean Ruby.
My non-scientific benchmark (dice.png):
without prawn-fast-png
real 0m5.102s
user 0m3.784s
sys 0m0.364s
with prawn-fast-png
real 0m0.482s
user 0m0.324s
sys 0m0.048s
So around 10x difference.
From my tests the size of the image increases, execution time grows
pretty fast. Now imagine how long it would take to insert 1000x4000
PNG? :)
Greetings,
Wojciech
> Your benchmark shows some speed up, but I wouldn't have messed with
> RMagick for such a small improvement. You either have a speedy machine
> there or you are embedding a small image.
Or a PNG without alpha layers. Prawn is only slow when it needs to
split out the alpha channel.
Something like 1s seems 'fine' to me.
> I needed to insert
> ~1000x4000 sized PNGs with alpha channel and that was simply not
> possible with clean Ruby.
>
> My non-scientific benchmark (dice.png):
> without prawn-fast-png
> real 0m5.102s
> user 0m3.784s
> sys 0m0.364s
>
> with prawn-fast-png
> real 0m0.482s
> user 0m0.324s
> sys 0m0.048s
>
> So around 10x difference.
Yep, there's the bottleneck, and a very nice result with your patch Wojciech.
Why don't we have you run this as a third party extension for now
(like Prawnto) and see how it goes?
I'll add a link in the README and image API docs once you have something up.
Feel free to use the Prawn mailing list if you wish to discuss this
extension with its users. Even if it's an "unofficial" project for
now, it's something I'd be happy to support.
-greg
Sounds good! At this point I was thinking about releasing it as a gem
through GitHub. Any thoughts on this?
Greetings,
Wojciech
Though I think any serious gem deserve distribution through RubyForge,
that's fine by me, go for it.
-greg
Gem is available now on GitHub as amberbit-prawn-fast-png.
Ok, let's distribute it through RubyForge too. I'm waiting for the new
project approval from RF admins.
Greetings,
Wojtek