rzel / unladen-swallow

Automatically exported from code.google.com/p/unladen-swallow
0 stars 0 forks source link

Look into faster string concentration for templating languages? #9

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
A central part of templating languages is the way they combine multiple strings 
into one string 
during template runtime.

The current most often used pattern seems to be a BufferIO class like the one 
from spitfire 
(http://code.google.com/p/spitfire/source/browse/trunk/spitfire/runtime/template
.py):

class BufferIO(list):
  write = list.append

  def getvalue(self):
    return ''.join(self)

The constrains of templating languages have even more minimal requirements than 
the built-in 
list used above, namely they care only about appending of multiple Unicode 
strings and a one-
time combination of those into a single Unicode string. As no slicing, 
retrieval of individual 
values or anything like it is required, I'm wondering if a more fine-tuned 
version of this could 
result in noticeable differences for the spitfire test cases. Using a 
collections.deque instead of a 
list here, doesn't produce any real difference.

Original issue reported on code.google.com by hanno...@gmail.com on 28 Mar 2009 at 2:29

GoogleCodeExporter commented 8 years ago
Instead of wondering, you can write up a patch or extension module and use 
perf.py to
test your theory. We probably won't get to micro-optimizations like this, but 
you
could validate your idea, post it to PyPI if it requires an extension module, 
and
then convince the templating engines to adopt it.

Original comment by jyass...@gmail.com on 28 Mar 2009 at 3:54