vb.org Archive

vb.org Archive (https://vborg.vbsupport.ru/index.php)
-   vB4 Programming Discussions (https://vborg.vbsupport.ru/forumdisplay.php?f=252)
-   -   Performance: preg_replace or hardcoded? (https://vborg.vbsupport.ru/showthread.php?t=276718)

Maccrob 01-10-2012 07:20 AM

Performance: preg_replace or hardcoded?
 
Hi all,
I have plugins which adds some data to forumbits etc by using $thread[] array and hardcoded html with something like {vb:raw thread.mydata}.
Which approach is the better from the position of performance: to parse template_compile and use e.g. preg_replace, or just hardcoded piece of html into existent template?

Disasterpiece 01-10-2012 08:56 AM

I recommend using preg_replace only if:

- the amount of text is "not too much" in one request
- the data may change often
- the replacement is context-sensitive, which means a normal str_replace is not sufficient
- the data needs to be fresh (non-cached)

It would be helpful to get a more specific example on what you actually want to do.

Maccrob 01-10-2012 12:32 PM

Example: add data after
Code:

<li id="forum1" class="forumbit_post L2">
on forumhome.
First variant: get needed data $thread[‘mydata’] and use str_replace in template_compile hook to append it after <li

Second variant: add html to forumhome_forumbit_level2_post template.
Code:

<li id="forum1" class="forumbit_post L2">{vb:raw thread.mydata}
Of course, for plugin creators, first variant is more suitable due simplest integration with different templates. In second variant we should manually add some code to templates.

So, from the position of performance which variant is better?

Disasterpiece 01-10-2012 01:57 PM

In any case it's better to use second way with the template system, because templates get cached. So this text gets generated once every few minutes, depending on the cache lifetime and can be viewed by hundrets of users.

The first method would replace a small text into a huge text for every site request, thus increasing the server load unnecessarily.

Also, it's more clean to use the templates as they are intended.


All times are GMT. The time now is 06:16 AM.

Powered by vBulletin® Version 3.8.12 by vBS
Copyright ©2000 - 2025, vBulletin Solutions Inc.

X vBulletin 3.8.12 by vBS Debug Information
  • Page Generation 0.01136 seconds
  • Memory Usage 1,710KB
  • Queries Executed 10 (?)
More Information
Template Usage:
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_header_end
  • (1)ad_header_logo
  • (1)ad_navbar_below
  • (2)bbcode_code_printable
  • (1)footer
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (6)option
  • (1)post_thanks_navbar_search
  • (1)printthread
  • (4)printthreadbit
  • (1)spacer_close
  • (1)spacer_open 

Phrase Groups Available:
  • global
  • postbit
  • showthread
Included Files:
  • ./printthread.php
  • ./global.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/class_hook.php
  • ./includes/modsystem_functions.php
  • ./includes/class_bbcode_alt.php
  • ./includes/class_bbcode.php
  • ./includes/functions_bigthree.php 

Hooks Called:
  • init_startup
  • init_startup_session_setup_start
  • init_startup_session_setup_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • style_fetch
  • cache_templates
  • global_start
  • parse_templates
  • global_setup_complete
  • printthread_start
  • bbcode_fetch_tags
  • bbcode_create
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • printthread_post
  • printthread_complete