is YII slow or did i smtg wrong?

hi!

at the moment i try to rewrite my old page with using YII.

this is my old page(sorry can not use links with http becasue i have not enough posts) :

ratmbootlegs.bplaced.net/?mid=4

everything is written with hand, no framework used. it is really fast.

now i created a similiar page with YII:

ratmbootlegs.bplaced.net/yiitest/demos/test/

the YII page is really slow (generation time can be see on the bottom of the pages). I don’t know if i did something wrong or if YII is little bit slow with all the framework overhead?

here is my YII code:

Controller:


        

        $criteria = new CDbCriteria;

        $criteria->with = array(

            'rectype',

            'concert',

            'concert.artist',

            'concert.country',

            'concert.city',

            'concert.venue',

            'video' => array('joinType' => 'INNER JOIN'),

            'video.videoformat',

            'medium',

            'source'

        );


        $dataProvider = new CActiveDataProvider('Record',

                        array(

                            'criteria' => $criteria,

                            'pagination' => array(

                                'pageSize' => 1000,

                            ),

                            'sort' => $sort,

                        )

        );


        $this->render('index', array(

            'dataProvider' => $dataProvider,

        ));



View:




<?php 


$this->widget('zii.widgets.grid.CGridView', array(

    'dataProvider'=>$dataProvider,

    'columns'=>array(

        array(

            'name'=>'artist',

            'value'=>'stripslashes($data->concert->artist->name)',

        ),  

        'concert.date',

       array(

            'name'=>'country',

            'value'=>'(( $data->concert->country == NULL ) ? "" : stripslashes($data->concert->country->name))',

        ),  

        array(

            'name'=>'city',

            'value'=>'(( $data->concert->city == NULL ) ? "" : stripslashes($data->concert->city->name))',

        ),

        array(

            'name'=>'venue',

            'value'=>'(( $data->concert->venue == NULL ) ? "" : stripslashes($data->concert->venue->name))',

        ),

        array(

            'name'=>'length',

            'value'=>'( $data->sumlength == NULL ) ? "" : $data->sumlength." min"',

        ),

        array(

            'name'=>'quality',

            'value'=>'$data->quality==NULL ? "" : $data->quality."/10"',

        ),   

        array(

            'name'=>'type',

            'value'=>'(($data->rectype == NULL ) ? "" : stripslashes($data->rectype->shortname))',

        ),

        array(

            'name'=>'medium',

            'value'=>'(($data->video->videoformat == NULL ) ? "" : $data->video->videoformat->label)." ".(($data->medium == NULL ) ? "" : $data->medium->label)',

        ),

        array(

            'name'=>'source',

            'value'=>'( $data->source == NULL ) ? "" : $data->source->shortname',

        ), 

        array(

            'name'=>'version',

            'value'=>'($data->sourceidentification)',

        ), 

    ),

));


?>



is there any way to improve the speed of my YII page? i really like YII with all the features, but if it is really slow like this i can not longer use it.

First you should add




$criteria->together = true;



which will enforce a single db query.

/Tommy

thansk for your answer… i added this line, but i can not really see any speed improvement.

GridView is not the fastest thing when there are many rows. The problem only grows when multiple tables are involved. With your pagesize at 1000 I am assuming you are putting out a lot of data.

One example. In one app I have a city table with about 15000 entries it works fine but then I have another table of location that ties a given user to a location with a fk from the city table. Just the gii generated code will take more then 15 seconds to render the grid with less then 5 entries in the location table. Other times it will just eat up the memory and not even display the grid giving a Fatal error: Allowed memory size of … bytes exhausted

To overcome this, I just created a view as a direct copy of my location table and the problem went away. For further refinement in other parts of the app another view combines the city, user, and location tables (appropriate attributes).

I have read enough problems in the past with gridview and large datasets but once I came up with this it hasn’t been a concern for me and so haven’t looked back. Would be curious how other overcome it though.

Maybe it is just that big clock around your neck FlavorFlav that makes it seem like time is passing slowly!

thanks for your help, but that was not really the answer i hoped to hear ;D

so maybe i will stay with my old implementation without YII and integrate a sorting algorithm myself.

I don’t think that this is a Yii problem. There are so many things regarding databases/apps that can cause performance problems. Wrong database configuration, overcomplicated queries. One thing people tend to forget when working with Yii is that ActiveRecord models aren’t ment to be used with 1000’s of records. AR is really handy for simple CRUD stuff but in your case I would try to take the DAO approach. This will definitely make it a lot faster although “not that convenient” to develop

Here is a link to the docs explaining Yii’s DAO functionalities: http://www.yiiframework.com/doc/guide/1.1/en/database.dao

i will check this out!