Views: 8146
Last Modified: 22.09.2014

The main idea of optimization in terms of the amount of information and cache consists in selecting and storing in cache of only required data and not all the data.

Selecting all the data may require more time and significantly increase the cache size.


Important Examples of Performance Enhancement

  1. Some API methods may generate excessive information. It is recommended that queries be limited to required data only early on.

    Example:

    $rs = CIBlockResult::GetNext(true, false);
    // setting the parameter false permits limiting the selection to the transformed values of fields only.
    $res = CIBlock::GetList(array(), array('TYPE'=>'catalog', 'SITE_ID'=>SITE_ID, 'ACTIVE'=>'Y'), false);
  2. Sometimes the method Fetch works faster than GetNext, but it does not make the data safe.
  3. Caching of required data only.

    In the component itself the result of its operation $arResult shall be limited to the required data only.

    For example, a component must display the element identifier and its name, and then only this element identifier and its name must be brought to cache:

    $this->SetResultCacheKeys(array("ID", "NAME"));

    If you perform any operations in result_modifier.php in order to transfer their result to component_epilog.php, keys in SetResultCacheKeys will also have to be installed. In this case, the result of the operations will also be cached.

    foreach ($sAr as $key => $arElement)
    {
    $this->__component->arResult["IDS"][] = $arElement["ID"];
    }
    $this->SetResultCacheKeys(array("IDS"))

    Note: If no keys are installed in SetResultCacheKeys, then, by default, all the results of $arResult will be cached.

    Links on the Subject:


  4. Cache size optimization.

    If, for example, the size of the cache file exceeds 1MB, excessive caching might be under way. In this case, cached data should be analyzed. The more the cache file size is, the less efficient it is.

  5. Limiting the volume of requested information.

    You can also enhance the performance by displaying information in parts.

    Displaying all information at once, for example, list of news for the entire year, is not recommended. In most cases, it is not needed and extremely inefficient. Displaying just the latest news of the day is enough.

    The system has several methods for limiting data selection by quantity. E.g., using a page navigation for the list of news, the selection can be limited to, say, 20 elements per page, and if the user goes to the next page, the next 20 elements will be requested and displayed.

    Example:

    The parameter nPageSize=20 of the array arNavStartParams permits displaying 20 elements, but it makes 2 database queries:

    1. "COUNT" - obtaining the number of elements
    2. "SELECT" - data selection proper
    

    while the parameter nTopCount=4 of the same array creates query 1-n as follows:

    SELECT * FROM tbl LIMIT 4;  
    

    The use nTopCount is much more efficient, because it makes no additional query in order to obtain selection entries.

  6. If own component is being created and queries will be needed to obtain different data, it is recommended that an option should be introduced in the component settings which will determine the data to be obtained. This way, the data that are unnecessary at this very moment will not be requested each time.


Courses developed by Bitrix24