Smarty Forum Index Smarty
WARNING: All discussion is moving to https://reddit.com/r/smarty, please go there! This forum will be closing soon.

Can this make smarty faster?

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General
View previous topic :: View next topic  
Author Message
stanleyxu2005
Smarty Rookie


Joined: 31 Dec 2006
Posts: 5

PostPosted: Sun Dec 31, 2006 2:44 pm    Post subject: Can this make smarty faster? Reply with quote

I have made a comparation about loading templates.

blank template ~> 0.0065 second
template with lot of content ~> 0.0135 second

It seems that to load "Smarty.class.php" takes much time.
The file smarty.class.php and smarty_compiler is roughly 140kb.
Does it make sense to remove all comments from smarty library, in order to make smarty library more lightweight?

I have just ported my website to smarty-template based. Each page requires at least 0.0135 second (previously was 0.002 second) This is a big difference. And the cpu usage is also much more. (I am afraid, when many users are viewing website at a same time, the server will be overload.)

You can see the difference at
http://gosurfbrowser.com/?&ln=en (pages are generated dynamically with simply php code)
http://gosurfbrowser.com/v2/?&ln=en (with smarty-template)

The configuration code is:
$tpl->compile_check=true;
$tpl->debugging=false;
other settings are used default values.
Back to top
View user's profile Send private message
Pap
Smarty Regular


Joined: 21 Jun 2006
Posts: 69
Location: Denver, CO

PostPosted: Sun Dec 31, 2006 8:20 pm    Post subject: Reply with quote

I suggest you use this:
http://php.net/manual/en/ref.apc.php

It will keep your most commonly requested PHP files cached in memory in bytecode format. Compiling to bytecode automatically removes comments, whitespace, etc, and leaves only pure computer instructions.
_________________
Don't be stupid, be a Smarty™.
Come and join the P-H-Party.
Back to top
View user's profile Send private message
stanleyxu2005
Smarty Rookie


Joined: 31 Dec 2006
Posts: 5

PostPosted: Sun Dec 31, 2006 8:59 pm    Post subject: Reply with quote

Thanks.

I have found a comment remover, but the difference is not obvious.
http://www.devpro.it/remove_phpcomments/

APC is a good solution, but it is required to be installed on server. This is not always possible. The better way is to find the bottleneck in Smarty.
Back to top
View user's profile Send private message
Hielke Hoeve
Smarty Elite


Joined: 06 Jan 2006
Posts: 406
Location: Netherlands

PostPosted: Mon Jan 01, 2007 7:36 pm    Post subject: Reply with quote

Comments in files are not a significant factor in the loading of php files.

If you use alot of filters and such the page loading time will indeed be somewhat higher, have you tried using caching?
_________________
Debug XHTML Compliance
SmartyPaginate
Smarty License Questions
---
(About Unix) The learning curve is full of aha! moments, such as that glorious day that the full beauty of grep and, later, find is revealed in all its majesty. --- Robert Uhl <ruhl@4dv.net>
Back to top
View user's profile Send private message
stanleyxu2005
Smarty Rookie


Joined: 31 Dec 2006
Posts: 5

PostPosted: Wed Jan 03, 2007 5:19 pm    Post subject: Reply with quote

I have not used any plugins at all.

About caching: the difference is not that much. I have mentioned, if I just create an instance without loading any template. It takes already 0.0065s. (If I generate a Web page with PHP code manually, it takes only 0.002s) This is a big difference.

My machine:
+ Intel Core Duo E6400
+ 2GB DDR 667
+ 320GB SATA 2.0
+ Windows XP SP2 with all patches.
+ PHP 4.4.2 (with Zend optimizier)

I think my machine is fast enough, but it still takes roughly at least 0.0135s to create a simple Web page. Will Smarty bring any performance issue, when many users are navigating web site at the same time?
Back to top
View user's profile Send private message
stanleyxu2005
Smarty Rookie


Joined: 31 Dec 2006
Posts: 5

PostPosted: Wed Jan 03, 2007 5:23 pm    Post subject: Reply with quote

The code of my benchmark timer
Code:

class TmxTimer {
   var $startTime;
   var $totalTime;

   //
   // Constructor
   //
   function TmxTimer() {
      $this->totalTime= 0;
      $this->start();
   }

   /**
    * Gets the current timestamp
    * @return float  Timestamp
    */
   function _getMicrotime() {
      list ($usec, $sec)= explode(' ', microtime());
      return ((float) $usec + (float) $sec);
   }

   /**
    * Starts timer
    */
   function start() {
      $this->startTime= $this->_getMicrotime();
   }

   /**
    * Stops timer
    * @return string  Total duration
    */
   function stop() {
      $duration= $this->_getMicrotime() - $this->startTime;
      $this->totalTime += $duration;
      return sprintf('%.4f', $duration);
   }
}


My index.php
Code:

include_once ('timer.php');
$timer= new TmxTimer();
$timer->start();

include_once ('smarty/Smarty.class.php');
$tpl= new Smarty;

/* display time and close */
echo $timer->stop();


The web page displays a time between 0.0044s and 0.0060s

To note that: If I create a Web page (like http://gosurfbrowser.com/), with
+ multilanguage support, with
+ dynamic content (load my own designed templates, data files, etc)
It takes only 0.002s

Rolling Eyes
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jan 04, 2007 8:13 am    Post subject: Reply with quote

stanleyxu2005 wrote:
Will Smarty bring any performance issue, when many users are navigating web site at the same time?


Probably. Test it.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Hielke Hoeve
Smarty Elite


Joined: 06 Jan 2006
Posts: 406
Location: Netherlands

PostPosted: Thu Jan 04, 2007 2:10 pm    Post subject: Reply with quote

With page loads in the 100s and 1000s of a second you will probably need alot of users and/or webpages that do lots of things. especially with a dual core processor.

Personally you should only be worried when loading times start to rise upto (half) a second when alot of users are using your site (100+?). Research shows users are often content when pages get loaded within a few second, this is ofcourse including client side rendering. Ofcourse it is good practice to prevent something rather than fixing it afterwards.
_________________
Debug XHTML Compliance
SmartyPaginate
Smarty License Questions
---
(About Unix) The learning curve is full of aha! moments, such as that glorious day that the full beauty of grep and, later, find is revealed in all its majesty. --- Robert Uhl <ruhl@4dv.net>
Back to top
View user's profile Send private message
stanleyxu2005
Smarty Rookie


Joined: 31 Dec 2006
Posts: 5

PostPosted: Thu Jan 04, 2007 2:30 pm    Post subject: Reply with quote

Hielke Hoeve wrote:
With page loads in the 100s and 1000s of a second you will probably need alot of users and/or webpages that do lots of things. especially with a dual core processor.

dual core processor is my test machine. I have rent a virtual host as web server. It is shared with many other customers. 0.0135s is tested with my machine. On the real web server, it performs much slower. Usallay 0.02-0.05s.

I just wondered, even when I do nothing with smarty, just including it. It takes much time. It does much in background. Are they really required?

I have seen some other template engines: smarty light, template lite. They say they are faster than smarty. My question is that I just use the very basic features of smarty, those are supported by other template engines as well. Why smarty is slower?
Back to top
View user's profile Send private message
messju
Administrator


Joined: 16 Apr 2003
Posts: 3336
Location: Oldenburg, Germany

PostPosted: Thu Jan 04, 2007 2:35 pm    Post subject: Reply with quote

stanleyxu2005 wrote:
I just wondered, even when I do nothing with smarty, just including it. It takes much time. It does much in background.


look into the source it what it does:

Code:

/**
 * DIR_SEP isn't used anymore, but third party apps might
 */
if(!defined('DIR_SEP')) {
    define('DIR_SEP', DIRECTORY_SEPARATOR);
}

/**
 * set SMARTY_DIR to absolute path to Smarty library files.
 * if not defined, include_path will be used. Sets SMARTY_DIR only if user
 * application has not already defined it.
 */

if (!defined('SMARTY_DIR')) {
    ### if you think the dirname system call is too expensive then define SMARTY_DIR before
    define('SMARTY_DIR', dirname(__FILE__) . DIRECTORY_SEPARATOR);
}

if (!defined('SMARTY_CORE_DIR')) {
    define('SMARTY_CORE_DIR', SMARTY_DIR . 'internals' . DIRECTORY_SEPARATOR);
}

define('SMARTY_PHP_PASSTHRU',   0);
define('SMARTY_PHP_QUOTE',      1);
define('SMARTY_PHP_REMOVE',     2);
define('SMARTY_PHP_ALLOW',      3);

/**
 * @package Smarty
 */
class Smarty
{
    ... here come only var and method definitions but *no* execution of anything
}


Quote:
Are they really required?


yes.
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Smarty Forum Index -> General All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group
Protected by Anti-Spam ACP