Please login or register.

Login with username, password and session length
Advanced search  

News:

You need/want an older version of sNews ? Download an older/unsupported version here.

Pages: [1] 2 3 4

Author Topic: [MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)  (Read 40059 times)

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955

This MOD provides for 2-3 times faster sNews page generation when applied in comparison with default sNews setup for versions 1.5.31 and 1.6.

Some time ago I was a lil' bit frustrated ( as if there is such a thing as a lil' bit frustrated Codie  :mad: ) due to fact that bullet proof performance optimization tricks stopped to work at all on sNews (like in no improvements to notice). After resorting to some investigation I stumbled upon a singular performance killer item - function get_id().

So, here is my version of get_id() with decent performance profile (as in doesn't matter any more in great scheme of all performance relevant things):

v.1.2 - 2008-01-22 - minor bugfix

(0) Backup snews.php (or just say something like 'hells bells' if U are true macho)

(1) First add following functions to snews.php right after original get_id() function (or include from separate file):
Code: [Select]
// Real GET parameter handler
function getGetParm( $parmName ) {
   $url = explode('/', $_GET['category']);
   switch ($parmName) {
      case 'category' :
         if ( $url[0] ) {
            // Fix to support sitemap.xml
            //$parmValue = cleanGetSef( $url[0] );
            $parmValue = ($url[0] == 'sitemap.xml') ? $url[0] : cleanGetSef( $url[0] );
         }
         break;
      case 'article' :
         if ( $url[1] ) {
            $parmValue = cleanGetSef( $url[1] );
         }
         break;
      case 'commentspage' :
         if ( $url[2] ) {
            $parmValue = cleanGetSef( $url[2] );
         }
         break;
      // Fix to support article subpage mod
      case 'subtitle' :
         if ( $url[2] ) {
            $parmValue = cleanGetSef( $url[2] );
         }
         break;
      default :
         $parmValue = false;
         break;
   }
   if ( isset($parmValue) && !($parmValue === false) ) {
      return $parmValue;
   }
}

// While called cleanGetSef() this actually doesn't 'clean' anything - it either returns value as is or returns nothing or boolean false
function cleanGetSef( $inSef ) {
   if ( $inSef == '' ) {
      $sef = '';
   }
   elseif ( is_numeric($inSef) && ( $inSef == (int) $inSef ) ) {
      $sef = (int) $inSef;
   }
   else {
      // String presumed
      // Fix to deal with voluntary wrong filenames requested
      //if (! preg_match('/^[a-z0-9-_#]+$/', $inSef) ) {
      if (! preg_match('/^[a-z0-9\-_#\.]+$/', $inSef) ) {
         // $inSef is malformed - ignored completely
         $sef = false;
      }
      else {
         // $inSef is ok - only lower case ascii, '-', '_', '#' and '.' characters are included
         $sef = $inSef;
      }
   }
   return $sef;
}
(2) Then comment out old get_id() and add next to it this, new one:
Code: [Select]
function get_id( $parameter ) {
   return getGetParm($parameter);
}
(3) And at last ... fasten seatbelts, Your sNews instance is lightweight again :lol:

History
 v.1.2 - 2008-01-22 - minor update of cleanGetSef() function to fix numeric sef value checking
 v.1.1 - 2007-06-28 - added mod compatibility fixes

Rights
Addon code (c) 2007 Valdis Ozols aka codetwist
Released under Creative Commons Attribution.

Special thanxes to bramsyuur (for setting up public demo) and tarmithius13 (for looking into paginator issues) ;)

P.S. for coders: Actually, function to use with caution is cleanXSS(); use it only when really needed.
« Last Edit: January 22, 2008, 03:24:12 PM by codetwist »
Logged

Mika

  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 9
  • Posts: 1408
    • http://www.ni5ni6.com/
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #1 on: May 23, 2007, 01:02:54 PM »

Not bad, codetwist ;)
Logged
http://www.ni5ni6.com/ - Tutorials, Mods and How-To's about sNews CMS
sNews 1.6 Developers Edition - commented sNews 1.6 version

amak

  • Newbie
  • *
  • Karma: 4
  • Posts: 41
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #2 on: May 23, 2007, 04:36:32 PM »

Hmm tried this on my local 1.5.31 and it seems to mess around with pages ... means:

- first article in category is shown correctly
- if i click on page 2, 3 or further there's always the content from article 1 shown

Any suggestions?
Logged
Regards,
Amak

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #3 on: May 23, 2007, 08:08:52 PM »

@amak : No ideas yet for possible cause - I tried it out before releasing here with paginator pages as well and looked now again. It works for me without problems :/

@Mika : Thx ;) Have You tried it out?

Can somebody else come up with info of how this one works for them? Same problem as for amak? No problems?
Logged

tarmithius13

  • Sr. Member
  • ****
  • Karma: 7
  • Posts: 476
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #4 on: May 23, 2007, 08:10:40 PM »

Works with 1.6 so far on a local install with three articles, the setting in admin for the frontpage is two articles and no issues seen. I will add more and see what it does.
Logged
The trick to flying is to throw yourself at the ground and miss.

Free sNews templates HERE

bramsyuur

  • sNews Dude
  • Hero Member
  • *****
  • Karma: 23
  • Posts: 900
    • http://snews.vietbee.net
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #5 on: May 23, 2007, 08:46:13 PM »

For more info on this:

Original sNews 1.6 Installation here (original get_id function) (no mods added in the core)
Modified sNews 1.6 Installation here (modified get_id function) (no mods added in the core)

See at the bottom of both installations the performance in seconds.
Both installations have access to the same database. No differences only the get_id thing.
Logged
La comunidad sNews en tu idioma!
Comunidad sNews en Español

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #6 on: May 23, 2007, 10:06:38 PM »

@bramsyuur : Thx a zillion :D It's better to see for real the difference on live internet site than to look into some profiling reports ;)
Logged

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #7 on: May 23, 2007, 10:10:35 PM »

Between, some credits should go to following tools : xdebug and WinCacheGrind ;)
Logged

piXelatedEmpire

  • MIA
  • Thread Moderator
  • ULTIMATE member
  • *****
  • Karma: 37
  • Posts: 1454
  • currently MIA
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #8 on: May 24, 2007, 02:00:59 AM »

that's a notable performance difference!  Love it codie more more more!!

 :cool:
Logged
my apologies to the sNews crew, but I will be MIA for the forseeable future

bobcat

  • Jr. Member
  • **
  • Karma: 1
  • Posts: 67
    • ESL Jobs by Country
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #9 on: May 24, 2007, 02:10:47 AM »

Thanks Bram for the demo, makes it nice and clear.

And of course thanks codetwist for this great modification  :D  :D  :D

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #10 on: May 24, 2007, 09:50:49 AM »

God, mo'n it is done in almost half he time ;)... Cool addition, Doug. I'm a bit worried due to your PS, though... Care to explain more for a non coder ? Is there any dangers with this ?
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs

codetwist

  • Hero Member
  • *****
  • Karma: 50
  • Posts: 955
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #11 on: May 24, 2007, 10:33:37 AM »

No dangers ;)
That cleanXSS() just do a lot of code execution - that means slower response time. When really controlled data sanitization is needed - like to clean inputs for further storage in database - then cleanXSS() probably is quite good choice. But for functions like get_id() much simpler checks do good enough ;)
Logged

Patric Ahlqvist

  • Nobodys perfect, but Im pretty effing close
  • Administrator
  • ULTIMATE member
  • ******
  • Karma: 65
  • Posts: 4957
  • “I'm a self-made man and worships my creator.”
    • p-ahlqvist.com
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #12 on: May 24, 2007, 10:44:23 AM »

Thanks.
Logged
My sNews site
"It's only dead fish that goes with the flow... "
Updated, online again - Free designs

Armen

  • Sr. Member
  • ****
  • Karma: 41
  • Posts: 338
    • http://www.funnydays.ru
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #13 on: May 25, 2007, 05:16:01 PM »

Dude!

Thousands of thx!

Three times faster... Now sNews has got back its most important factor - speed.
Logged
Now ogres, oh, they're much worse. They'll make a suit from your freshly peeled skin. They'll shave your liver, squeeze the jelly from your eyes... Actually, it's quite good on toast.

mosh

  • Dev Invitee
  • Hero Member
  • *****
  • Karma: 78
  • Posts: 522
  • Awesome day :)
[MOD] Performance booster - get_id() on steroids (v.1.6, 1.5.31)
« Reply #14 on: May 25, 2007, 06:44:49 PM »

:P  :P  :P  :P  wow.
thanks code  :cool:
Logged
Pages: [1] 2 3 4