Issue Bug Closed

#63666High memory consumption in BackendUtility->getTCAtypes while bulk inserting

Stephan Großberndt 12/08/14, 14:14 updated 10/02/18, 11:48

Description

DataHandler->fillInFieldArray calls
$types_fieldConfig = BackendUtility::getTCAtypes($table, $currentRecord);
for each record to insert. In each call the type of the current record is checked and the complete types configuration is parsed again.
static public function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
    if ($GLOBALS['TCA'][$table]) {
    // Get type value:
    $fieldValue = self::getTCAtypeValue($table, $rec);
    // Get typesConf
    $typesConf = $GLOBALS['TCA'][$table]['types'][$fieldValue];
    // Get fields list and traverse it
    $fieldList = explode(',', $typesConf['showitem']);
    $altFieldList = array();
    // Traverse fields in types config and parse the configuration into a nice array:
    foreach ($fieldList as $k => $v) {
        [...]
    }
    if ($useFieldNameAsKey) {
        $fieldList = $altFieldList;
    }
    // Return array:
    return $fieldList;
}

A new static cache using tablename, type and parameter as key improves performance and memory consumption:

static public function getTCAtypes($table, $rec, $useFieldNameAsKey = 0) {
    static $tcaTableTypeConf_cache = array();

    if ($GLOBALS['TCA'][$table]) {
    // Get type value:
    $fieldValue = self::getTCAtypeValue($table, $rec);

    if ($tcaTableTypeConf_cache[$table . 'type' . $fieldValue . 'fnk' . $useFieldNameAsKey]) {
        return $tcaTableTypeConf_cache[$table . 'type' . $fieldValue . 'fnk' . $useFieldNameAsKey];
    }

    // Get typesConf
    $typesConf = $GLOBALS['TCA'][$table]['types'][$fieldValue];
    // Get fields list and traverse it
    $fieldList = explode(',', $typesConf['showitem']);
    $altFieldList = array();
    // Traverse fields in types config and parse the configuration into a nice array:
    foreach ($fieldList as $k => $v) {
        [...]
    }
    if ($useFieldNameAsKey) {
        $fieldList = $altFieldList;
    }

    $tcaTableTypeConf_cache[$table . 'type' . $fieldValue . 'fnk' . $useFieldNameAsKey] = $fieldList;
    // Return array:
    return $fieldList;
}
For bulk insert of 6500 typeless (only type ‘1’) records:
  • 465000 calls less
  • 3.3 seconds faster
  • memory usage of explode()-Function down from 128MB to 58MB

Reviews 2