简体   繁体   中英

How to improve CGridView's performance in Yii

I am just curious about the performance of CGridView in Yii Framework. I built a simple app with Yii. on a Model's admin page, simply listing all records, with pagination (30/page) , and custom sorting, which is working great so far.

But I find that it takes 4-5 seconds to render the CGridView. Is it normal to render a 30 records page in 4-5 secs? I kind of feel it's slow! Because it's not a complicated table, with only 8 columns. And the SQL query generated is running fast (done in 2-3 ms), although including a few relations.

I googled a lot on the optimization, and found this official document: http://www.yiiframework.com/doc/guide/1.1/en/topics.performance

Focus on the CGridView problem, I tried to use cache, and find COutputCache which is a really good helper.

My practice is add COutputCache in the filter() function of the Controller:

public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
        array(  'COutputCache+admin,_lists',   'duration' => 600,'varyByParam'=>array('sort','page'),     ),
    );
}

You could add normal view pages and also the partial page, set the expire time in seconds, and tell Yii which parameter to detect the cache change.

And this helps a lot when you re-visit the page, including sorting and paging. Low down page render time to 40-50 ms which is awesome!

But I haven't found a good way to speed up the first time rendering. Do you have any good suggestions?

在我的情况下,性能低的原因是使用数据列的html类型。

First, display your log in your webpage to see what is going on so we can help.

Second, no, it is not normal. ¿What server are you on? Are you using CActiveRecord relations? how many? maybe the answer is just to use CDbCriteria.with to do not lazy load the related tables.

您必须检查排序,每当排序字段不是索引时,您将从Yii构建的查询中获得缓慢的结果

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM