Patchwork [2,of,3] templater: resurrect cache of engine instance

login
register
mail settings
Submitter Yuya Nishihara
Date June 22, 2018, 12:49 p.m.
Message ID <9a00b95221eb92f0df92.1529671756@mimosa>
Download mbox | patch
Permalink /patch/32378/
State Accepted
Headers show

Comments

Yuya Nishihara - June 22, 2018, 12:49 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1529587650 -32400
#      Thu Jun 21 22:27:30 2018 +0900
# Node ID 9a00b95221eb92f0df923315911e61641a4e0054
# Parent  dd2cf66485226a05fab5ef69edf975f2e51214e6
templater: resurrect cache of engine instance

The engine-level cache was effectively disabled at 48289eafb37d "templater:
drop extension point of engine classes (API)" by mistake, which made template
rendering quite slow.

Spotted by Martin von Zweigbergk.

Patch

diff --git a/mercurial/templater.py b/mercurial/templater.py
--- a/mercurial/templater.py
+++ b/mercurial/templater.py
@@ -872,6 +872,8 @@  class templater(object):
         self.defaults = defaults
         self._resources = resources
         self._loader = loader(cache, aliases)
+        self._proc = engine(self._loader.load, self._filters, self.defaults,
+                            self._resources)
         self._minchunk, self._maxchunk = minchunk, maxchunk
 
     @classmethod
@@ -923,8 +925,7 @@  class templater(object):
     def generate(self, t, mapping):
         """Return a generator that renders the specified named template and
         yields chunks"""
-        proc = engine(self.load, self._filters, self.defaults, self._resources)
-        stream = proc.process(t, mapping)
+        stream = self._proc.process(t, mapping)
         if self._minchunk:
             stream = util.increasingchunks(stream, min=self._minchunk,
                                            max=self._maxchunk)