Edgewall Software

Ticket #6614: render-using-StringIO-rr6677.patch

File render-using-StringIO-rr6677.patch, 1.1 KB (added by cboos, 10 months ago)

This patch helps to reduce the maximal memory usage.

  • trac/web/chrome.py

    # HG changeset patch
    # User Christian Boos <cboos@bct-technology.com>
    # Date 1205339881 -3600
    # Node ID 7334686a938b90c35ef3cdc058ad7f007cb900bc
    # Parent  fbf91c6896bdb00dd0bdb5a1e1c5206777b569f6
    Avoid creating a big unicode string while rendering the stream.
    
    We retrieve the generated content in chunks and encode it to UTF-8 directly.
    
    diff -r fbf91c6896bd -r 7334686a938b trac/web/chrome.py
    a b  
    1919import pkg_resources 
    2020import pprint 
    2121import re 
     22 
     23from cStringIO import StringIO 
    2224 
    2325from genshi import Markup 
    2426from genshi.builder import tag, Element 
     
    701703        }) 
    702704 
    703705        try: 
    704             return stream.render(method, doctype=doctype) 
     706            buffer = StringIO() 
     707            for chunk in stream.serialize(method, doctype=doctype): 
     708                buffer.write(chunk.encode('utf-8')) 
     709            return buffer.getvalue() 
    705710        except: 
    706711            # restore what may be needed by the error template 
    707712            req.chrome['links'] = links