phpBB

Development Discussion Board

phpBB's testing ground of bleeding edge code
Advanced search

Make phpBB faster/liter by replacing dynamic strings with static one

General discussion of development ideas and the approaches taken in the 3.x branch of phpBB. The next feature release of phpBB 3 will be 3.1/Ascreaus followed by 3.2/Arsia.

Make phpBB faster/liter by replacing dynamic strings with static one

Postby Shaban Sunal » Fri Aug 17, 2012 6:52 am

Hi everyone! :mrgreen: I was just customizing my phpBB's template..when i saw so many dynamic strings that could be made static..The first thing that comes in my mind is by replacing the "U" (Url variable) and "L" (Language variable) variables with the static ones; for example: {U_Search} ----> http://www.websiteurl.com/search.php and: {L_Search} ----> Search. Don't you think that making them static will avoid the template file calling everytime the many variables set in the common file and elsewhere (loading the server more than the necessary too), instead of just "showing" them to the user's browser? We will let Apache "calm down" and make the html work :mrgreen: thus LESS SERVER LOAD ;) I know you will say 'yeah but everyone needs to set his own static variable according to his website's url and language'...well..you can simply make a php form that modifies all the variables in the template files (or elsewhere) given the website's url that is inserted into the textfield, and for the language are taken from a preexisting language file ;) so what do you think about it? :)
Shaban Sunal
Registered User
 
Posts: 5
Joined: Fri Aug 17, 2012 6:24 am

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby Shaban Sunal » Fri Aug 17, 2012 1:07 pm

Nobody? at least..can someone tell me if i should do this or not? ;)
Shaban Sunal
Registered User
 
Posts: 5
Joined: Fri Aug 17, 2012 6:24 am

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby Ger » Fri Aug 17, 2012 1:35 pm

Don't you think they're variables for a reason?
Above message may contain errors in grammar, spelling or wrongly chosen words. This is because English isn't my mother tongue. My apologies in advance.
User avatar
Ger
Registered User
 
Posts: 176
Joined: Mon Jul 26, 2010 1:55 pm
Location: 192.168.1.100

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby Shaban Sunal » Fri Aug 17, 2012 1:57 pm

Yes, but once you are ready to make that forum live (and also before) variables/strings such as "{U_SEARCH}" and "{U_LOGIN}" for example will most likely remain fixed/unchanged...tell me..why in the world should you change the search url (one in the middle of the jungle of the other potential static strings of course)? I've already tried to and i saw an improvement in the CPU usage and the page's loading time ;)
Shaban Sunal
Registered User
 
Posts: 5
Joined: Fri Aug 17, 2012 6:24 am

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby imkingdavid » Fri Aug 17, 2012 2:45 pm

Well, for one thing, if you have multi-lingual users, you will not be able to take advantage of language packs if you hardcode the text into the template. Also, if you ever decide to change a string of text, and it appears in multiple locations, it is significantly more work to change it everywhere it appears than to simply change the language string in a single file.

One reason links are not hardcoded, aside from a similar reason above (not having to change multiple uses of the same link multiple times), internal links are passed through append_sid() so that the session is always sure to be kept. If you hardcode the links, in some cases your users may lose their session and have to re-login, which is an inconvenience for them.

In any case, keep in mind that if you hardcode all these links and URLs in your template, you will have a difficult time updating because the automatic updater will not know how to handle all of that, so you will have to do it manually.

I doubt that any speed increase brought about by removing template variables is significant enough to justify such a major change.
I do custom MODs. PM for a quote!
View My: MODs | Portfolio
Please do NOT contact for support via PM or email.
Remember, the enemy's gate is down.
User avatar
imkingdavid
Development Team
Development Team
 
Posts: 900
Joined: Thu Jul 30, 2009 12:06 pm

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby callumacrae » Fri Aug 17, 2012 3:09 pm

It's a negligible performance gain, in my opinion.
"In JavaScript, there is a beautiful, elegant, highly expressive language that is buried under a steaming pile of good intentions and blunders"
—Douglas Crockford

View my MOD, phpBB Mobile
User avatar
callumacrae
Website Team
Website Team
 
Posts: 881
Joined: Tue Apr 27, 2010 9:37 am
Location: England

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby Shaban Sunal » Fri Aug 17, 2012 4:18 pm

imkingdavid wrote:Well, for one thing, if you have multi-lingual users, you will not be able to take advantage of language packs if you hardcode the text into the template. Also, if you ever decide to change a string of text, and it appears in multiple locations, it is significantly more work to change it everywhere it appears than to simply change the language string in a single file.

One reason links are not hardcoded, aside from a similar reason above (not having to change multiple uses of the same link multiple times), internal links are passed through append_sid() so that the session is always sure to be kept. If you hardcode the links, in some cases your users may lose their session and have to re-login, which is an inconvenience for them.

In any case, keep in mind that if you hardcode all these links and URLs in your template, you will have a difficult time updating because the automatic updater will not know how to handle all of that, so you will have to do it manually.

I doubt that any speed increase brought about by removing template variables is significant enough to justify such a major change.


That wouldn't be a problem; you don't need to edit every string by hand one by one..you could make a php file with a str_replace function just to say one. You're right 'if you ever decide' ;) no one would be so insane to go changing a string every now and then..the only reasons can be if you change domain/folder. But anyway the work is done one time, and not everytime like when the pages are loaded, get it?
I just changed some other strings and i've no error of any sort, including that of sessions..i'm still logged in ;) Can you give me some of the incriminated strings?

callumacrae wrote:It's a negligible performance gain, in my opinion.

Well..consider that the CPU load decreased by a 29% ;)
Shaban Sunal
Registered User
 
Posts: 5
Joined: Fri Aug 17, 2012 6:24 am

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby DavidIQ » Fri Aug 17, 2012 9:14 pm

You completely ignored the part about multi-languages. If we were to go with what you're suggesting then there would have to be multiple versions of template files if there are different languages available on a board. I'm sure going through all template files to produce the desired language to display won't do your CPU usage any favors either. ;)

The template engine in 3.1 has already been redone so I'm pretty sure you'll be seeing improvements there anyways.
Image
User avatar
DavidIQ
MOD Team Leader
MOD Team Leader
 
Posts: 753
Joined: Thu Mar 02, 2006 4:29 pm
Location: Earth

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby Oleg » Sat Aug 18, 2012 2:44 am

It is fairly straightforward to perform this replacement on a single installation via regular expressions. Therefore I would like to see some benchmarks. Also, with and without APC for 4 total benchmarks.
Oleg
3.1 Release Manager
3.1 Release Manager
 
Posts: 1150
Joined: Tue Feb 23, 2010 2:38 am

Re: Make phpBB faster/liter by replacing dynamic strings with static one

Postby drathbun » Sat Aug 18, 2012 3:09 pm

I find it hard to believe that a few variable versus static replacements dropped cpu utilization by nearly a third. :-?
Sometimes you're the windshield, sometimes you're the bug.
User avatar
drathbun
Registered User
 
Posts: 72
Joined: Wed Feb 15, 2006 6:40 pm
Location: Texas

Next

Return to [3.x] Discussion

Who is online

Users browsing this forum: Exabot [Bot] and 7 guests