Idea: local variable caching of filters/filter stacks

Issue #217 new
created an issue

Analyzing the generated .py files from my current project, there's lots of this pattern, as my default_filters are {{{['h', 'unicode']}}}:


so it would seem to make sense, to reduce name lookups (in favor of LOAD_FAST) to either

  • cache the filter callables as locals in the function (as is being done with {{{M_writer}}}) to something like {{{ M_f_unicode = unicode M_f_filtershtml_escape = filters.html_escape }}}
  • and/or maybe better yet create a single cached callable for all of these filter "stacks": {{{ M_f_unicode_filtershtml_escape = lambda args,*kwargs: M_f_unicode(M_f_filtershtml_escape(args,*kwargs)) }}} and have the codegen use those instead.

I haven't studied the codegen more deeply to find out what sort of magic this would require though :)

Comments (1)

  1. Michael Bayer repo owner

    not to mention turning all those write() calls into one:

    __M_writer("foo %s bar %s" % (

    all good things.

  2. Log in to comment