[Zope] extensive Looping in DTML considered harmful

Joachim Schmitz js@ac-copy.net
Thu, 3 Feb 2000 22:29:20 +0100 (CET)


cause it can take all your cpu  for some seconds.
Here is what I had:

<dtml-in Events >
<tr>
<td><dtml-var firma>
<br>Tel: <dtml-var tel>
</td>
<dtml-call "REQUEST.set('temps',_.string.split(_vars['zeiten'],'/'))">
<dtml-call "REQUEST.set('siz',_.string.split(temps,'('))">
<dtml-if "_.len(siz) > 1" >
  <dtml-call "REQUEST.set('wt',_.string.split(siz[1][:-1],','))">
  <dtml-call "REQUEST.set('siz',siz[0])">
<dtml-else>
  <dtml-call "REQUEST.set('wt',tage)">
  <dtml-call "REQUEST.set('siz',siz)">
</dtml-if>
  <dtml-in tage>
  <dtml-call "REQUEST.set('tag',_vars['sequence-item'])">
    <td valign="top" bgcolor="#e3e8ff" align="center" width="85">
    <font face="ARIAL,HELVETICA" size="2" color="#3c5282">
    <dtml-in zz>
      &nbsp;
      <dtml-call "REQUEST.set('st',_vars['sequence-item'][1])">
        <dtml-comment>
        <dtml-var st>
        </dtml-comment>
        <dtml-if "tag in st">
          <dtml-var "_['sequence-item'][0]"> <br>
        <dtml-else>
          <br>
        </dtml-if>
    </dtml-in >
    </font></td>
  </dtml-in>
  </tr>
</dtml-in >

that was basically it the outer <dtml-in> SQLmethod resulted in about 60
rows, the inner was done for every weekday i.e. 7 times. This resulted on 
an Ultrasparc in an executiontime of 10 CPU seconds, on a Sparc 20 it took
more than a minute with a CPU load of nearly 100 %.

I implemented the above in Class for the SQL-method, so the above was
replaced by
<dtml-var xyz> with xyz being a method of the class, which produced the
same output as above. Besides being much more clear, cause it's pure
Python, it takes now less than 0.5 CPU seconds on the Ultrasparc.

Just wanted to share that experience :-)
  

Mit freundlichen Grüßen

Joachim Schmitz

WWW-Consultant

email: js@ac-copy.net
tel: +49-241-89491-0
fax: +49-241-89491-29