On Jul 21, 4:56 pm, "[EMAIL PROTECTED]"
<[EMAIL PROTECTED]> wrote:
>
> def render(table, _context=None, target_language=None):
>     global generation
>
>     (_out, _write) = generation.initialize_stream()
>     (_attributes, repeat) = generation.initialize_tal()
>     (_domain, _negotiate, _translate) = generation.initialize_i18n()
>     (_escape, _marker) = generation.initialize_helpers()
>     _path = generation.initialize_traversal()
>
>     _target_language = _negotiate(_context, target_language)
>     _write('<table>\\n')
>     for row in table:
>         _write('<tr>\\n')
>         for column in row.values():
>             _write('<td>')
>             _tmp1 = column
>             _urf = _tmp1
>             if isinstance(_urf, unicode):
>                 _write(_urf)
>             elif _urf is not None:
>                 _write(_escape(_urf))
>             _write('</td>')
>         _write('</tr>')
>     _write('</table>')
>
>     return _out.getvalue()

Yeah, so here is the mako render() method for that template:

def render_body(context,**pageargs):
    context.caller_stack._push_frame()
    try:
        __M_locals = __M_dict_builtin(pageargs=pageargs)
        table = context.get('table', UNDEFINED)
        __M_writer = context.writer()
        # SOURCE LINE 1
        __M_writer(u'\n<table>\n')
        # SOURCE LINE 3
        for row in table:
            # SOURCE LINE 4
            __M_writer(u'   <tr>\n')
            # SOURCE LINE 5
            for col in row.values():
                # SOURCE LINE 6
                __M_writer(u'       <td>')
                __M_writer(filters.html_escape(unicode( col )))
                __M_writer(u'</td>\n')
            # SOURCE LINE 8
            __M_writer(u'   </tr>\n')
        # SOURCE LINE 10
        __M_writer(u'</table>\n')
        return ''
    finally:
        context.caller_stack._pop_frame()

I think this source code is extremely comparable to the z3c.pt
code....the Mako has less initialization code at the top.   You might
want to maybe test against a wider range of template designs to get a
better picture of the speed differenes.   Is it literally just the
html_escape(unicode()) that makes z3c 2x the speed ?   Cheetah as
well ?  It seems like Mako could apply the exact same optimizations
with no trouble at all.

>
> spitfire's main trick is to first generate a Python abstract syntax
> tree out of the template and then have multiple loops of various
> optimization's being applied to that tree, so it can optimize away
> even more.
>

well if you've generated Python code as we've done here, you can get
an AST from that.   I think its the "various optimizations" part here
that is somewhat mysterious :).

Are you planning on applying Spitfire's techniques to z3c?  If so, I
might as well do whatever you're doing too since the code generation
is extremely similar.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pylons-discuss" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/pylons-discuss?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to