[Typo3-dev] Heavy use of stdWrap -> speedproblem

Alexander Langer alex at big.endian.de
Mon May 24 11:32:07 CEST 2004


Also sprach Georg Rehfeld (georg.rehfeld at gmx.de):

> You ain't talking about a HTML template file with four thousand five
> hundred markers/subparts, do you? If so, I immediately would expect
> some havy misconception, but please explain your concept a little bit
> more.

Check this:
You have a template or an item ITEM, let's call it TEMPLATE_ITEM.
now, within the TEMPLATE_ITEM subpart, there _might_ occur 20 different
markers, such as

ITEM_TITLE
ITEM_PARENT
ITEM_URL
ITEM_DATE
ITEM_TEASER
ITEM_FOOBAR
ITEM_POMMES
...

(up to 30-50 properties).  In real life, only 3 or 5 are used, but as I
want to be flexible, I want to let the website author fill the template
with any subset he wants to use.

However, if you want to fill in the template, you need to fill the
markerArray with _all_ those values:

$markers = array();
$markers['###ITEM_TITLE###'] = $this->cObj->stdWrap("the Title", ...);
$markers['###ITEM_PARENT###'] = $this->cObj->stdWrap(the Parent, ...);
$markers['###ITEM_DATE###'] = $this->cObj->stdWrap(the date, ...);
... [all of the markers, also with subparts + wrappedsubparts ]
$content = subsitituteMarkerArrayCached($markers, $subparts, $wrappedsubparts);

Now, as I happen to display ~150 items per page (don't ask, why), this
will result in filling ~450 markers (I currently don't know how I came to
4500 yesterday) before substituting.

This is - as you can expect, very slow.

I now improved speed by scanning the template for actually used markers
before filling the array.  This improves speed by factor 10, which is
good enough for me.

However, would be nice to have a
substituteMarkerArrayCallback($template, $theCallbackfunction, $theArgs)

that could be used like this:

function myCallback($theMarker, $theArgs) {
	// $theArgs contains my stuff
	list($myData1, $myData2) = $theArgs;
	switch($theMarker) {
	case '###ITEM_TITLE###':
		return $this->cObj->stdWrap(theTitle, ...);
	case '###ITEM_PARENT###':
		return $this->cObj->stdWrap(theParent, ...);
	}
}

and substituteMarkerArrayCallback would do something like:

{
	scan for the next (###.*###) (marker, subparts etc)
	$marker[theFoundMarker] = $theCallbackfunction(theFoundMarker, $theArgs);
	(until all markers are filled)

	return substituteMarkerArrayCached($marker, $subparts, ...);
}

This would probably improve speed a lot for big markers.

Alex





More information about the TYPO3-dev mailing list