Precompiling Taglibs

37 views
Skip to first unread message

Tom Locke

unread,
Sep 8, 2009, 7:54:39 AM9/8/09
to Hobo Users
Hi Folks

A couple of people have requested the ability to have DRYML taglibs
compiled during app startup, as opposed to the first time they are
used. This has a particular benefit with Passenger, as it allows the
memory used by the taglibs to be shared across the Passenger instances
(required Ruby Enterprise Edition? I'm not sure).

Anyway, it turned out to be extremely easy, just add lines like this
to an initialiser (e.g. config/initializers/hobo.rb)

Hobo::Dryml::Taglib.get :src => "taglibs/application"

If you're on edge, you can do this (just pushed to master):

Hobo::Dryml.precompile_taglibs

Which will find all .dryml files in your main taglibs directory and
any plugins, and precompile them all.

I'd be very interested to hear from anyone about improvements to
memory consumption as a result of this trick (Matt!)

Cheers

Tom

Matt Jones

unread,
Sep 10, 2009, 4:18:27 AM9/10/09
to hobo...@googlegroups.com

On Sep 8, 2009, at 7:54 AM, Tom Locke wrote:

>
> Hi Folks
>
> A couple of people have requested the ability to have DRYML taglibs
> compiled during app startup, as opposed to the first time they are
> used. This has a particular benefit with Passenger, as it allows the
> memory used by the taglibs to be shared across the Passenger instances
> (required Ruby Enterprise Edition? I'm not sure).
>
> Anyway, it turned out to be extremely easy, just add lines like this
> to an initialiser (e.g. config/initializers/hobo.rb)
>
> Hobo::Dryml::Taglib.get :src => "taglibs/application"
>
> If you're on edge, you can do this (just pushed to master):
>
> Hobo::Dryml.precompile_taglibs
>

Note that this will cause 'rake hobo:generate_taglibs' to die horribly
if you've got app/views/taglibs/auto .gitignored. This line in an
initializer will make things play nice:

Hobo::Dryml.precompile_taglibs if File.basename($0) != "rake" &&
Rails.env.production?

It also avoids precompiling the taglibs in development and test, as
it's not particularly useful there.

On my live application, it didn't seem to noticeably reduce memory
usage (on REE); BUT it did make starting up new worker instances
considerably faster (under load, several would try to start at once
and all be compiling the same sources). That makes it easier to just
keep the workers recycling every hour or so and helps the memory usage
issues.

--Matt Jones

Tiago Franco

unread,
Sep 10, 2009, 11:54:07 AM9/10/09
to Hobo Users
Hi Tom,

Are you considering in having this configuration out of the box?

TF
Reply all
Reply to author
Forward
0 new messages