logo       
Google Custom Search
    AddThis Social Bookmark Button
-->

Re: Prepared statement: msg#00011

Subject: Re: Prepared statement
On 4/19/06, Alan Pinstein <apinstein@xxxxxxx> wrote:
> Got some initial figures...
>
> After some profiling I've learned that the implementation of the
> cache (having to hash the sql statement as the key) yields basically
> no benefit.
>
> This confused me, since in my code implementing the hash actually
> improved runtime dramatically. Looking into it further I realized
> that another expensive thing was being saved during a cache hit:
>
> >     public function prepareStatement($sql)
> >     {
> >         if (isset($this->preparedStatementCache[$sql]))
> >         {
> >             $stmt = $this->preparedStatementCache[$sql];
> >         }
> >         else
> >         {
> >             require_once 'creole/drivers/pgsql/
> > PgSQLPreparedStatement.php';
> >             $stmt = new PgSQLPreparedStatement($this, $sql);
> >             $this->preparedStatementCache[$sql] = $stmt;
> >         }
> >         return $stmt;
> >     }
>
> The "require_once" statement!
>
> This is very slow on some machines. Avoiding it saved a ton of time.
> I talked about this in detail when implementing the autoload code for
> Propel.
>
> Thus, I removed all of my "cache" code and simply moved the
> require_once statement to the top of the page and now it's even
> faster than it was with the prepared statement cache because there is
> no overhead, just pure savings.
>
> Any downside to moving this line around in the CVS version? Isn't the
> most common use of creole for propel? If so, propel uses prepared
> statements for everything, so I'd think that this fix would be a net
> positive.

There will still be able to be some performance ripped out of
replaceparams if you want to get hardcore on the optimizations here.

I used creole for a long time before i used propel and i also used it
without using the preparedstatement's for a long time, its not a good
assumption to make.

for the sake of benchmarking...

     public function prepareStatement($sql)
     {
        static $loaded = false;
        if ( $loaded !== true ) {
            require_once 'creole/drivers/pgsql/PgSQLPreparedStatement.php';
        }
        return new PgSQLPreparedStatement($this, $sql);
     }

i think thatll work, see how that goes?


Cameron
<Prev in Thread] Current Thread [Next in Thread>