Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMartin Langhoff <martin@laptop.org>2010-11-24 20:55:52 (GMT)
committer Martin Langhoff <martin@laptop.org>2010-11-25 21:04:53 (GMT)
commit88e9df6c58827f3d812a956688afad29be4e28f8 (patch)
tree460965f54f869ef5ccd66203adb49cc5566c43b3
parente5d1d0793bedc06cfee4b9c580d681ca318f3fb8 (diff)
Use lrudecorator to memoize wp_load_article lookups
Reading profiling data on wp_load_article points to wp.wp_load_article() being called many times, and being slow. This patch gives us radical speedups on cached stuff, and modest cache results. Andorra goes from 15.5s to 14.5s cold-cache. Once the cache is seeded it returns in 0.7s.
-rwxr-xr-xmwlib/expander.py7
-rwxr-xr-xserver.py9
2 files changed, 10 insertions, 6 deletions
diff --git a/mwlib/expander.py b/mwlib/expander.py
index 6298c7f..e5e4049 100755
--- a/mwlib/expander.py
+++ b/mwlib/expander.py
@@ -10,6 +10,7 @@ import re
import os
from mwlib import magics
import mwlib.log
+from pylru import lrudecorator
DEBUG = "DEBUG_EXPANDER" in os.environ
@@ -424,6 +425,7 @@ class Expander(object):
for line in f.readlines():
self.blacklist.add(line.rstrip().decode('utf8'))
+ @lrudecorator(100)
def getParsedTemplate(self, name):
if name.startswith("[["):
return None
@@ -435,10 +437,6 @@ class Expander(object):
if len(name) > 1:
name = name[0].capitalize() + name[1:]
name = "Plantilla:" + name
- try:
- return self.parsedTemplateCache[name]
- except KeyError:
- pass
# Check to see if this is a template in our blacklist --
# one that we don't want to bother rendering.
@@ -463,7 +461,6 @@ class Expander(object):
print "TEMPLATE:", name, repr(raw)
res.show()
- self.parsedTemplateCache[name] = res
return res
diff --git a/server.py b/server.py
index 406d45b..9b301be 100755
--- a/server.py
+++ b/server.py
@@ -37,6 +37,7 @@ import tempfile
import re
import wp
import xml.dom.minidom
+from pylru import lrudecorator
# Uncomment to print out a large dump from the template expander.
#os.environ['DEBUG_EXPANDER'] = '1'
@@ -110,7 +111,7 @@ class WPWikiDB:
article_text = ""
break
- article_text = unicode(wp.wp_load_article(title.encode('utf8')), 'utf8')
+ article_text = unicode(wp_load_article(title.encode('utf8')), 'utf8')
# To see unmodified article_text, uncomment here.
# print article_text
@@ -763,6 +764,12 @@ def load_db(dbname):
dbname + '.locate.prefixdb',
dbname + '.blocks.db')
+# Cache articles and specially templates
+@lrudecorator(100)
+def wp_load_article(title):
+
+ return wp.wp_load_article(title)
+
def run_server(confvars):
index = ArticleIndex('%s.index.txt' % confvars['path'])