Moving "import trml2pdf" in shipping.views to displayDoc function to improve start up speed

Issue #976 resolved
ledzep2 created an issue

I used profiler middleware which uses cProfile module inside to profile the response time of the first request after server start.

The profiler shows:

{{{ Ordered by: internal time

ncalls tottime percall cumtime percall filename:lineno (function)

266/191 0.183 0.001 1.224 0.006 {import} 1 0.083 0.083 0.093 0.093 pdfmetrics.py:5() 16 0.078 0.005 0.788 0.049 views.py:1() 1 0.073 0.073 0.073 0.073 satchmo_util.py:1() 1 0.067 0.067 0.067 0.067 pdfutils.py:4() 2 0.047 0.023 0.047 0.023 init.py:17() 1 0.044 0.044 0.047 0.047 utils.py:4() 4 0.031 0.008 0.117 0.029 forms.py:1() 1 0.031 0.031 0.501 0.501 trml2pdf.py:23() 1 0.029 0.029 0.074 0.074 satchmo_category.py:1() 2 0.025 0.013 0.028 0.014 sre_compile.py:307 (_optimize_unicode) 1 0.024 0.024 0.127 0.127 paragraph.py:4() 1 0.024 0.024 0.286 0.286 canvas.py:3() 276 0.024 0.000 0.061 0.000 base.py:244(init) ...

}}} As you can see trml2pdf and pdf related scripts are on top of the list. So I tried to comment "import trml2pdf" and tested.

Before commenting "import trml2pdf"

153720 function calls (150045 primitive calls) in 1.606 CPU seconds

After commenting "import trml2pdf"

133991 function calls (130889 primitive calls) in 1.133 CPU seconds

So this is a reduce of 20,000 function calls and 30% performance increase. And in my point of view, trml2pdf is not really needed at the first stage of server start. So I suggest to move it inside "displayDoc" function.

Comments (3)

  1. Cristian Ciupitu

    I don't think that it's worth trading readability for a fraction of a second at startup.

    Also, what Python (and Django) are you using and what's the speed difference between the original displayDoc function and the modified one?

  2. Former user Account Deleted

    I'm using Django trunk (1.1) and python 2.5. I didn't profile the displayDoc function.

    I care about the startup speed because on some shared host (like Bluehost which I'm using) satchmo may need to be initialized frequently. Since fastcgi daemon is not allowed, module cache time is limited, the whole site could be reloaded on a random request. I think startup speed is crucial in this case.

  3. Log in to comment