1

I'm writing a mercurial extension, but am finding that template rendering is rather slow.

I was originally using cmdutil.rendertemplate(), however, it seems that has to reparse the template string every time, which is rather slow.

When switching to the "new" api for @templatekeyword, it looks like the first arg passed is a mercurial.templater.engine object, which has an expand method that caches the parsed versions of templates, which makes it much faster. Unfortunately, it doesn't expand aliases.

Does anyone know the Right Way to efficiently render templates and aliases for a mercurial extension? Right now, the only option I see is copy/pasting the portions of cmdutil.rendertemplate and keeping my own global cache...but that feels pretty icky.

Richard Levasseur
  • 14,562
  • 6
  • 50
  • 63

1 Answers1

0

Suppose you need to

  • render a user template loaded from somewhere other than the [templates] section,
  • in a keyword function,

the current way is to put the loaded template to templater.cache[name] first [1], and render it by context.process(name, mapping) [2].

  1. https://www.mercurial-scm.org/repo/hg/file/4.7.1/mercurial/cmdutil.py#l2643
  2. https://www.mercurial-scm.org/repo/hg/file/4.7.1/mercurial/templatekw.py#l474

I'm not sure if that's the case you're facing. There might be a better way depending on context.