Edgewall Software

Changes between Version 22 and Version 23 of TracDev/Proposals/Jinja


Ignore:
Timestamp:
Mar 18, 2016, 10:24:07 AM (8 years ago)
Author:
Christian Boos
Comment:

copy some more precise memory usage results I got a while ago (Feb. 12)

Legend:

Unmodified
Added
Removed
Modified
  • TracDev/Proposals/Jinja

    v22 v23  
    6868In addition, while I didn't measure precisely the memory usage, Genshi made the python.exe process jump from 109MB to 239MB while rendering the request (blob). The memory seems to be freed afterwards (there were no concurrent requests). By contrast, with Jinja2 the memory spike was 106MB to 126MB.
    6969
     70In another experiment, I used the [pypi:memory_profiler] on Windows, which provided the following results when rendering a big changeset, for a rendered page weighing 3.53MB:
     71{{{
     72Genshi xhtml: 293.612 total (load=0.017, generate=0.017, filter=0.000, render=293.578)
     73Filename: d:\Trac\repos\trunk\trac\web\chrome.py
     74
     75Line #    Mem usage    Increment   Line Contents
     76================================================
     77  1283    101.6 MiB      0.0 MiB               @profile
     78  1284                                         def genshi():
     79  1285    101.6 MiB      0.0 MiB                   buffer = StringIO()
     80  1286    101.6 MiB      0.0 MiB                   t5 = time.time()
     81  1287    101.6 MiB      0.0 MiB                   stream.render(method, doctype=doctype, out=buffer,
     82  1288    153.2 MiB     51.6 MiB                                 encoding='utf-8')
     83  1289    158.0 MiB      4.9 MiB                   gs = buffer.getvalue().translate(_translate_nop,
     84  1290    158.0 MiB      0.0 MiB                                                    _invalid_control_chars)
     85  1291    158.0 MiB      0.0 MiB                   t6 = time.time()
     86  1292    158.0 MiB      0.0 MiB                   show_times('Genshi', t2 - t1, t4 - t3, t5a - t4a, t6 - t5,
     87  1293    158.1 MiB      0.0 MiB                              method)
     88  1294    158.1 MiB      0.0 MiB                   return gs
     89}}}
     90
     91
     92vs.
     93
     94{{{
     95Line #    Mem usage    Increment   Line Contents
     96================================================
     97  1255    101.6 MiB      0.0 MiB               @profile
     98  1256                                         def jinja(mode='render'):
     99  1257    101.6 MiB      0.0 MiB                   if jtemplate:
     100  1258    101.6 MiB      0.0 MiB                       j5 = time.time()
     101  1259    101.6 MiB      0.0 MiB                       if mode == 'render':
     102  1260    111.1 MiB      9.4 MiB                           js = jtemplate.render(jdata)
     103  1261    111.1 MiB      0.0 MiB                           j5a = time.time()
     104  1262    115.4 MiB      4.3 MiB                           js = js.encode('utf-8') \
     105  1263    115.4 MiB      0.0 MiB                                  .translate(_translate_nop,
     106  1264    106.7 MiB     -8.7 MiB                                             _invalid_control_chars)
     107  1265    106.7 MiB      0.0 MiB                           j6 = time.time()
     108  1266    106.7 MiB      0.0 MiB                           show_times('Jinja2', j2 - j1, 0, j5a - j5, j6 - j5a,
     109  1267    106.7 MiB      0.0 MiB                                      'html')
     110  1268    106.7 MiB      0.0 MiB                           return js
     111}}}
     112
    70113In summary, this means that for the big problematic pages, we can easily have a 10x speedup and more, by migrating to Jinja2, and this with a much lighter memory footprint.
    71114For smaller pages, the speed-up is between 5x to 10x as well.
     
    78121See also PortingFromGenshiToJinja/Example for a full example presented side-by-side.
    79122
     123[=#jinjachecker]
    80124In order to facilitate the creation of error-free Jinja2 templates for HTML (or XML), we also wrote a little utility called [PortingFromGenshiToJinja/Checker jinjachecker], which will help troubleshoot the most common nesting problems.