Search code examples
ratpackpebble

loading and compiling template in ratpack: blocking or not?


I'm adding Pebble template support to my ratpack application, and there is one matter that bothers me: should my RendererSupport instance use ratpack's Blocking.get() or not? As PebbleEngine has it's own cache, i can't say whether it would be loading template source from disk, so it is (possibly) an IO operation. Looking at handlebars templating implementation i can't see any special treat of the IO operation.

So my question is: is it the rule of thumb to use Blocking for all the potentially IO-bound operations (e.g. filesystem or db access), or there is some more complicated rule?


Solution

  • If Pebble's cache is indefinite (Handlebars' one is) then I would say you can do the same as what Ratpack's integration for Handlebars does - depend on the cache and run the code that can potentially load the template from disk on the compute thread. You will pay a performance penalty every time a template is loaded for the first time (because you will run blocking code on a compute thread) but it will go away as your cache coverage increases.

    Note that there is an issue in the tracker that aims at removing that performance penalty for the Handlebars integration by precompiling templates and thus populating the cache on startup.