SitePoint Sponsor

User Tag List

Page 1 of 5 12345 LastLast
Results 1 to 25 of 130

Hybrid View

  1. #1
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)

    Code comments and execution time

    Edit:


    This thread was split from http://www.sitepoint.com/forums/gene...de-739087.html

    -- ScallioXTX

    Quote Originally Posted by deathshadow60 View Post
    ...
    ...
    ...
    We aren't talking about compiled languages here where you can comment until blue in the face and it has zero impact on the binary.
    ...
    ...
    ...
    I like PHP comments which are stripped from the final browser output of the generated HTML and CSS:
    PHP Code:
    // HTML
        <?php /* ===================== START BLOCK ======================== */ ?>
      <div id='new_left'>
          <?php if (! LOCALHOST) { ?>
          <br />
                <div class='advert_728x90'>
                    <?php include 'adverts/_google_728x90.php'?>
                </div>
            <?php ?>
            
            <div>
             ...
             ...
             ...
            </div> 
        <?php /* ===================== END BLOCK ======================== */ ?>


    // CSS
    <?php 
    header
    ("Content-type: text/css;charset:UTF-8");// http://www.barelyfitz.com/projects/csscolor/  
    if(0){include'style.class_colors.php';} // http://www.typefolly.com/
    if(1){include'style.style_fonts.php';}
    if(
    1){include'style.style_dimensions.php';}
    if(
    0){include'user_1.php';}// blood,tangerine,banana,ocean,grass,coal
    if(1){include'user_2.php';}// blood,tangerine,banana,ocean,grass,coal
    $bgg1='eee';
    $cl2='900';
    $cl3='090';
    ?>
    body {background-color:#<?php echo $bf1;?>;color:#<?php echo $cl2;/* give this colour a whirl and see it is OK */ ?>}
    #new_left {clear:both;width:88%;margin:1em auto;border:double 2px #<?php echo $clr3;?>}

  2. #2
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    I like PHP comments which are stripped from the final browser output of the generated HTML and CSS:
    ... and I HATE to break it to you, but /FAIL/ hard. REALLY HARD.

    While you might not see comments in the output and bandwidth use, they DO take time to process on the server and as such slow down execution...

    since php is an INTERPRETED language. Now, PHP is a two stage bytecode interpreter; which is to say that it does a byte-code style compile before executing, but the inital parse still takes overhead for comments which is why stupid pointless comments (like a row of nothing but asterisks) should be avoided... Certainly a code caching accellerator (APM, eAccellerator) helps by caching the byte-coded version, but if your code ends up flushed from the cache those comments will incur their penalty again.

    Just because you don't see it in the HTML output doesn't mean they aren't incurring a penalty; in disk reads, in memory use, and in code parsing time on the server.

    Because PHP isn't a compiled language EITHER... nor is Perl, nor is Ruby, nor is ASP.

    Of course, switching in and out of parse mode like some rubbish "scripting" language doesn't help... there's a reason I consider any php code that does <?php ?> more than once to be a steaming pile of garbage.

    Which is why your PHP samples from above are... freakishly bad.

  3. #3
    SitePoint Mentor bronze trophy
    John_Betong's Avatar
    Join Date
    Aug 2005
    Location
    City of Angels
    Posts
    1,578
    Mentioned
    62 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    ... and I HATE to break it to you, but /FAIL/ hard. REALLY HARD.

    While you might not see comments in the output and bandwidth use, they DO take time to process on the server and as such slow down execution...

    since php is an INTERPRETED language. Now, PHP is a two stage bytecode interpreter; which is to say that it does a byte-code style compile before executing, but the inital parse still takes overhead for comments which is why stupid pointless comments (like a row of nothing but asterisks) should be avoided... Certainly a code caching accellerator (APM, eAccellerator) helps by caching the byte-coded version, but if your code ends up flushed from the cache those comments will incur their penalty again.

    Just because you don't see it in the HTML output doesn't mean they aren't incurring a penalty; in disk reads, in memory use, and in code parsing time on the server.

    Because PHP isn't a compiled language EITHER... nor is Perl, nor is Ruby, nor is ASP.

    Of course, switching in and out of parse mode like some rubbish "scripting" language doesn't help... there's a reason I consider any php code that does <?php ?> more than once to be a steaming pile of garbage.

    Which is why your PHP samples from above are... freakishly bad.
    I am aware and agree that processing on the server takes time and just included the repeated "===" for demonstration purposes only

    A friend of mine used to argue the point about programming execution speed , cost of hardware and programming time to optimise code.

    Fortunately I have a relatively fast server which manages to interpret and produce the browser output of eleven small images, Javascript Google Adsense, Google Analytics and quite a bit of text in under two seconds. The results can see on the the following link:

    Pingdom Tools

    If there is a faster way to produce HTML and CSS then I am always willing to learn, daily try to reduce the page speed and open to suggestions.

  4. #4
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by John_Betong View Post
    If there is a faster way to produce HTML and CSS then I am always willing to learn, daily try to reduce the page speed and open to suggestions.
    I'm going to respond to this via PM in a few minutes as we're starting to drift OT... My bad

  5. #5
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    Of course, switching in and out of parse mode like some rubbish "scripting" language doesn't help... there's a reason I consider any php code that does <?php ?> more than once to be a steaming pile of garbage.
    So you use smarty I take it?

    Mode switching has its place.

  6. #6
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    So you use smarty I take it?
    I'd sooner put a bullet in my head.

    Though I hate templating systems of the normal sort -- most of the time I end up screaming "Oh for crying out loud, just let me write the blasted PHP"

    Probably part of what I LIKE about skinning SMF.

    All you have to do is look at the retard code example on the site for smarty -- no self respecting PHP developer would write GARBAGE like this:

    Code:
    <?php if(!empty($foo)): ?>
      <?php foreach($foo as $bar): ?>
         <a href="<?=$bar['zig']?>"><?=$bar['zag']?></a>
         <a href="<?=$bar['zig2']?>"><?=$bar['zag2']?></a> 
         <a href="<?=$bar['zig3']?>"><?=$bar['zag3']?></a> 
      <?php endforeach; ?>
    <?php else: ?>
       There were no rows found.
    <?php endif; ?>
    The "smarty" version being:
    Code:
    {foreach $foo as $bar}
      <a href="{$bar.zig}">{$bar.zag}</a>
      <a href="{$bar.zig2}">{$bar.zag2}</a>
      <a href="{$bar.zig3}">{$bar.zag3}</a>
    {foreachelse}
      There were no rows found.
    {/foreach}
    Which of course doesn't actually INCLUDE THE IF STATEMENT making the code vague/meaningless if it's automatically doing that.,... all to do this:

    Code:
    if (!empty($foo)) {
      foreach($foo as $bar) {
        echo '
          <a href="',$bar['zig'],'">',$bar['zag'],'</a>
          <a href="',$bar['zig2'],'">',$bar['zag2'],'</a> 
          <a href="',$bar['zig3'],'">',$bar['zag3'],'</a>';
      }
    } else echo '
          There were no rows found.';
    With the <?php being once somewhere <on topic>way the **** **** up a the start of the program where it **** belongs</on topic> and the ?> occuring only once in the file <on topic>way the **** down at the ****** end</on topic>

    I really laugh at the IDIOCY whenever I see dumbass nimrod coding like this particular part:

    <?php if(!empty($foo)): ?>
    <?php foreach($foo as $bar): ?>

    What was that coder trying to accomplish other than writing garbage code with that nonsense?!? Of course I say that whenever I see IDIOCY like:

    <a href="<?php echo $bar['zig']; ?>">

    which goes hand in hand with the idiocy of trying to use double quotes to echo... which is rarely as useful as people think... and if you REALLY wanted to use double quotes

    echo "<a href='$bar['zig']'>";

    Would work too.... even if it does take longer to execute since you have the complex parser involved.

    Card stacking is the only excuse/explanation of that code; using an example of piss poor coding techniques to make their convoluted bloated system of nothingness look more useful than it actually is.

    Of course they try to sell that to you as reduced syntax time, failing to mention it's another layer of abstraction atop PHP that adds to the execution time defeating the entire POINT.

    Off Topic:

    This site really needs a facepalm smiley and a "crazy" smiley

  7. #7
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    Would work too.... even if it does take longer to execute since you have the complex parser involved.


    I don't think you quite get how the PHP interpreter reacts to the opening and closing takes, " vs. ' and heredocs vs. nowdocs. The situation is at best unclear. The difference in execution time between

    PHP Code:
    echo 'Lorem Ipsum '.$var.' no dolem.'
    and

    PHP Code:
    echo "Lorem Ipsum {$var} no dolem"
    Is nominal. Further - counter intuitively - the parser does the second version slightly faster.

    Second, it doesn't cost the parser time to move between PHP blocks. Any intervening text is silently converted to an echo statement. So moving between modes doesn't make the code dog slow.

    I'm studying C++ because I do want to make the parser modal at include time and no one else is interested in coding the project. This isn't so much for optimization as allowing framework designers to more strictly control the types of files that are included. The mod I'm working on allows the language to do the following.

    PHP Code:
    require( "file.php"); // For backwards compat php.ini settings honored.
    require( "include.php"PHP_TAGS_NONE ); // No tags will be allowed, whole file is assumed to be PHP code.
    require( "template.phtml"PHP_TAGS_SHORT ); // Short tags enabled for this include.
    require( "template2.tpl"PHP_TAGS_HEREDOC ); // No tags allowed, but variables such as {$var} will be evalutated as if the entire files was fed through the heredocs parser 
    In the PHP.ini file the default tag mode can be set, and if set the existing ASP_TAGS and SHORT_OPEN_TAGS settings get ignored.

    The goal is to allow the programmer to control the allowed parsing at require time with a goal towards further encouraging code separation and increasing security since dis-allowed markup cannot be placed in certain file types.

    Off Topic:

    Back off the bombastic arrogance please. It's annoying and insulting the the reader and a distraction from the content of your messages which is usually insightful and on point.

  8. #8
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    The difference in execution time between

    PHP Code:
    echo 'Lorem Ipsum '.$var.' no dolem.'
    and

    PHP Code:
    echo "Lorem Ipsum {$var} no dolem"
    Actually that makes perfect sense for the latter to run faster, it's not allocating memory to perform a string addition BEFORE the output. Swap those periods for comma's and it runs faster than the latter.

    Single quote parsing only has to scan for escaped singles and the close, double quote parsing has to scan for variables, multiple possible escaped values, AND inlined variables -- it's making the parser and interpreter do all the work...

    Off Topic:

    Quote Originally Posted by Michael Morris View Post
    Back off the bombastic arrogance please. It's annoying and insulting the the reader and a distraction from the content of your messages which is usually insightful and on point.
    You know, I'm really sick of this... ok, I'm not going to say it; I'd be banned if I said my real response to that. Are people REALLY so thin skinned?

    Oh wait, of course they are; so comfortable, so soft... and god forbid you say anything negative about ANYTHING.

    I was taught that when something stinks you rip it completely to shreds and say it stinks -- that's how you have PROGRESS. People who cannot stand the idea of calling stupid stupid, idiocy idiocy and nimrods nimrods typically end up with the 'status quo' mentality; the antithesis of progress.


    Though I like the idea of not allowing PHP includes to include markup... I wouldn't even BOTHER with the other ones, just make ALL php files be treated as your PHP_TAGS_NONE... I truly believe it was a mistake to EVER allow it to work any other way. I would love nothing better than to see <?php and ?> removed from the language ENTIRELY.

  9. #9
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    since php is an INTERPRETED language.
    This entire discussion has gone off course because PHP is NOT an interpreted language - it is a compiled language.

    It isn't comiled just once though with all subsequent accesses using the compiled version. It is compiled every time someone accesses the web page and the compiled version is run just for that one access and is then discarded with the script being compiled all over again when the page is next referenced.

    This is known as a Just in Time compile process (or JIT).

    You can tell that PHP is compiled and not interpreted because if there are any syntax errors in the code at all you get a syntax error message and none of the code gets run. If you consider an interpreted language such as JavaScript all of the code that can be run will be run up to the point where a syntax error occurs because the interpreter runs each statement separately before looking at the next.

    Now the compile step is going to run longer in order to skip over the comments in the code but the run step following will not have any comments to skip over.

    This will make a difference to the amount of impact that comment placement will have within the code. With an interpreted language such as JavaScript a comment inside a function or loop will need to be skipped over and slow down the processing each time that the function or loop runs and so moving the comment outside of the function or loop will speed up the processing. With PHP though while the comments will slow the compiler down they should all have the same effect regardless of where in the code that they are placed since the functions and loops will not be run until after the compiler finishes compiling the code and the version that actually gets run will not have any comments in it anywhere.

    So while each comment you place in PHP will slow down the processing it will not make any difference where you put the comments and comments inside a loop that runs millions of times will have the same effect as if the comment were outside the loop rather than being treated as a million separate comments the way it would in an interpreted language.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  10. #10
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by TomB View Post
    Firstly, [citation needed]? How many editors break? Lets do a poll to find out how many people find syntax highlitghting useful for productivity. I'm sure you are in a tiny minority.
    Crimson, Notepad++, the M$ one for .net, gEdit... Of course since acid trip is one of the first things I turn off...

    Quote Originally Posted by TomB View Post
    My point was enclosing HTML in PHP strings will lose the HTML tag matching and highlighting.
    Which I don't need because I know how to use the TAB and ENTER keys, and generally don't have block level containers long enough for them not to line up on screen.

    Quote Originally Posted by TomB View Post
    If you can't see the benefit in being able to quickly find the start tag for an end tag
    I do, that's why I'm rabid about hitting enter, tab, or shift-tab, or letting the auto-deindent do it's job.

    Quote Originally Posted by TomB View Post
    or letting the editor immediately tell you when you're missing a </div> then you really are just stuck in your ways.
    Which just gets in the way when it's in two separate functions, or two separate files... and practice the 76 column rule for code but not content.

    Quote Originally Posted by TomB View Post
    Or are you perfect? Let me guess, you never make mistakes....
    No, but I do practice decade old tried and true methods for preventing me from making the simpler mistakes in the first place...

    Quote Originally Posted by TomB View Post
    I see. Nostalgia is your argument here. Great, can we actually discuss things which have a practical benefit? And no, code formatting preferences are not practical.
    No offense, but spoken like someone not only over-reliant on their tools, but vomiting up code any old way. Lemme guess, classes on H1's, style tags in the markup for static values like width:auto; vague/meaningless three letter classnames and presentational classes like "right"? PRobably have some nice pointless IE conditionals on a layout that shouldn't even need real hacks to work properly all the way back to IE 5.x?

    Quote Originally Posted by TomB View Post
    I have no idea what this means. It's a series of correctly-spelled English words and it parses as a grammatically correct sentence, but beyond that "it sounds like ********".
    So... been programming all of six months to a year and never taken a single course or read a book on the subject? Or are the fundementals of elementary programming practices just not taught anymore?

    Indent style - Wikipedia, the free encyclopedia

    Quote Originally Posted by TomB View Post
    That silly level of abstraction is pointless isn't it?
    Abstraction isn't pointless -- abstraction without improvement or abstraction to avoid fixing something inherently wrong with what's underneath IS. The latter of those among programmers it's often called the "black box" syndrome -- rather than fix something directly, you just treat the core as invoilate and slap something else on top of it to handle the problem... Which in engineering parlance is basically duct tape, spit and bailing wire. It'll get the job done for a bit, but it usually comes back to bite you further down the road.

    The former is just bloat for nothing -- and is why Smarty to me is pointless; it offers no real improvements despite adding the overhead of an extra preprocessor atop a... preprocessor... I say much the same about jquery as I see no real improvements over just writing the code directly, and for the most part it's useless bloat ruining just about every website it's on from both a maintenance standpoint and from a user standpoint...

    Quote Originally Posted by felgall View Post
    This entire discussion has gone off course because PHP is NOT an interpreted language - it is a compiled language.

    It isn't comiled just once though with all subsequent accesses using the compiled version. It is compiled every time someone accesses the web page and the compiled version is run just for that one access and is then discarded with the script being compiled all over again when the page is next referenced.

    This is known as a Just in Time compile process (or JIT).
    WRONG... and right... Wait, what? Lemme explain.

    PHP does NOT compile to native machine language, the precompiler is to bytecode to run on a bytecode interpreter... so while it is "compiled" it is not TRULY compiled. Microsoft Gee-Whiz Basic did the same thing, we still call that an interpreted language! It may catch syntax errors before runtime; but that doesn't mean it's an actual compiled language. GW-Basic and most Microsoft ROM basics didn't let you enter lines of code with syntax errors on them or load ASCII copies of programs that had syntax errors -- nor did they store the code in memory as ASCII -- did that make them compiled languages? OF COURSE NOT! Hell, on pretty much every ROM basic and soft-basic interpreter "syntax error" is a EDITOR message, not a runtime error.

    The code still runs on an INTERPRETER instead of as MACHINE LANGUAGE. See the difference? It's not like it runs it through GAS to make a executable binary.

    It most certainly is NOT JIT compiled since the compile target is NOT machine language! It's bytecode compiled -- oh, and if you run a caching director like eAccellerator or APC, that bytecoded version of the page IS cached and not thrown away -- assuming there's room in the cache and it's frequently accessed enough! (I like to provide 256 megs of space to APC, which is more than the bytecode version of every .php file on my server combined)

    If we call PHP a compiled language, we'd have to call the BASIC interpreter on a ZX80 compiled, and that's just silly... much akin to the people who call XML a "machine readable format" or XML based "languages" machine readable -- Said people needing to go back and learn something about computers! If you have to run it through a parser to turn those integers from ascii into integers, reals from ascii into single,double or extended and strings into machine format null terminating or length prefixed strings, they're NOT any more machine readable than C or Pascal code... or Assembly language source; until it's turned into machine code or formats that the registers and opcodes can handle directly, it's NOT "Machine readable". Might be SOFTWARE readable...

    Bottom line -- compiling to bytecode to run on an INTERPRETER is NOT true compilation... and it sure as shine-ola isn't JIT compilation in any sense of the term.

  11. #11
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    This entire discussion has gone off course because PHP is NOT an interpreted language - it is a compiled language.

    It isn't comiled just once though with all subsequent accesses using the compiled version. It is compiled every time someone accesses the web page and the compiled version is run just for that one access and is then discarded with the script being compiled all over again when the page is next referenced.

    This is known as a Just in Time compile process (or JIT).
    While everything Felgal says here is true - I still would consider PHP a hybrid. In my opinion, any language which has run time evaluation -- an eval() statement -- is almost certainly interpreted and can be called an 'interpreted' language because for all practical purposes it is.

    Also, while simple parse errors are caught at the compile pass - symbol table mismatches, such as calls to non-existent functions aren't caught until the line tries to actually execute. In this manner PHP behaves more like an interpreted language than a compiled one. Java after all also uses JIT compiling from the bytecode to the final executable, but it catches many errors at compile time PHP does not. Java also does not have any eval capacity.

    Finally, as far as optimization goes, if APC cache or similar mechanism is present PHP can hold the bytecode between page requests and that code can persist for the lifetime of the cache, which has enormous returns in execution speed.

  12. #12
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,603
    Mentioned
    24 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by Michael Morris View Post
    While everything Felgal says here is true - I still would consider PHP a hybrid.
    This thread is discussing comments. Regardless of what the compile step outputs for PHP the comments will have already been stripped out. The overhead of having the comments only impacts on that compile step - what happens to it after that is the same as if the comments were not there at all.

    This is totally different from a purely interpreted language where the comments need to be skipped over every time you get to one.

    I agree that PHP is a hybrid but in so far as comments are concerned it behaves close to how compiled programs and nothing like interpreted ones.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">

  13. #13
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by felgall View Post
    This thread is discussing comments. Regardless of what the compile step outputs for PHP the comments will have already been stripped out. The overhead of having the comments only impacts on that compile step - what happens to it after that is the same as if the comments were not there at all.
    Except that on first-run or if you aren't running a caching accelerator that byte-code compile step happens whenever you call it. What you called the JIT still has to deal with it, even if the bytecode interpreter does not.

    ... and compilation is one of the slowest operations there is on a computer since its' basically a lexical parser; even though bytecode is nowhere near as bad as an ACTUAL compiler, especially if we were to talk a multi-target one. See why APM and it's kin offer such miraculous speedups -- they allow you to skip the plaintext to bytecode step IF the program is still in the cache.

    Quote Originally Posted by felgall View Post
    This is totally different from a purely interpreted language where the comments need to be skipped over every time you get to one.
    Which is why GW-B 4 was faster than 2.x -- comments were stored outside the byte-code and interpolated in realtime by the editor and list functions -- IF they were on their own line. NOT that 4 was around long enough to matter since quickBasic (an ACTUAL compiler) was released at almost the exact same time.

    Quote Originally Posted by felgall View Post
    I agree that PHP is a hybrid but in so far as comments are concerned it behaves close to how compiled programs and nothing like interpreted ones.
    Which I can agree to IF you are running a caching program like APC and IF have already run the code once and IF it's still in your cache and hasn't been flushed by something else... That's a lot of IF, and if none of those are true and it works as how you said in your post saying it's not interpreted -- instead of the comment taking time during bytecode interpretation it's just taking time during compiling the source into bytecode...

    Net change zero... though at least YES, there is relief in the form of eAccellerator, APC, etc, etc... It's just not bulletproof relief.

  14. #14
    SitePoint Wizard
    Join Date
    Oct 2005
    Posts
    1,770
    Mentioned
    5 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    While you might not see comments in the output and bandwidth use, they DO take time to process on the server and as such slow down execution...
    Yeah, by maybe 2/1000ths of a second.

    Quote Originally Posted by deathshadow60 View Post
    Of course, switching in and out of parse mode like some rubbish "scripting" language doesn't help... there's a reason I consider any php code that does <?php ?> more than once to be a steaming pile of garbage.
    I use PHP's alternate syntax exclusively when making templates. My sites execute very fast.

    The slowest part of doing anything in PHP is file access. Even slower still is database queries (which accesses tables in the file system). Compiling and executing PHP code is very fast, even with lots of comments and even with "dropping out" of the compiler by using PHP's alternate syntax with straight PHP code.

    Besides, how do you know how the PHP compiler executes behind the scenes to be able to say the alternate syntax slows things down by any significant amount?

    Quote Originally Posted by deathshadow60 View Post
    Probably part of what I LIKE about skinning SMF.
    Now I see where you are coming from. SMF is one of the biggest piles of crap ever written in PHP. Template code echoed out from here, there, and everywhere. It's plain awful. Difficult to modify. One big pile of spaghetti code. Mods open up existing files and dump ugly code right in the middle of SMF's ugly code.

    echo 'SMF really ';
    if (!empty($sucks))
    {
    echo 'sucks!';
    }

    Write some code for us and I'll rewrite it using PHP's alternate syntax and with tons of comments. Then we'll do a little comparison and see how much faster yours is.

    You want to see some slow code? Look at Wordpress 3.1. That thing has 76 separate files included on every pageview using the default template. Including a few things that are absolutely not needed.

    WordPress Support 77 Files Included Per Page View! Insane!

    If you want to speed up a site, limit the number of files included. File access is magnitudes slower than executing code with or without comments and alternate syntax. PHP can execute thousands of lines of code in the time it takes to seek and open one file from the hard drive.

  15. #15
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cheesedude View Post
    I use PHP's alternate syntax exclusively when making templates. My sites execute very fast.
    AGAIN speed aside, that has to be maintennence NIGHTMARE code-wise.

    Quote Originally Posted by cheesedude View Post
    The slowest part of doing anything in PHP is file access. Even slower still is database queries (which accesses tables in the file system).
    that's true of anything on computers -- Disk access remains the largest bottleneck... including the disk access time of reading in that .php file.

    Quote Originally Posted by cheesedude View Post
    Besides, how do you know how the PHP compiler executes behind the scenes to be able to say the alternate syntax slows things down by any significant amount?
    Because I've written lexical analysis programs, compilers and interpreters giving me a decent clue how they work? It might not be a significant amount, BUT AGAIN if it provides ANY benefit and is just a simple change in code writing behavior requiring no extra REAL effort to do it... why all the griping about it even being suggested?

    Quote Originally Posted by cheesedude View Post
    Now I see where you are coming from. SMF is one of the biggest piles of crap ever written in PHP.
    Funny since I say the same thing about vBull, phpBB and myBB... and those are some of the BETTER ones. vBulletin 4 in particular being one such a train wreck it makes wordpress 2 look good. (gotta love that 170k of markup to deliver 16k of plain text, 6k of that plain text being content cloaking nonsense thanks to the use of non-semantic markup applied under the banner of semantics)

    Quote Originally Posted by cheesedude View Post
    Template code echoed out from here, there, and everywhere.
    I wasn't aware that self contained directories of theme.functionName.php files for each theme constituted "here, there and everywhere"... In fact I'm fairly certain that it makes it EASIER for skinners than having to dive into the code that handles database and data interactions to make changes... without completely neutering what the skinner can do using those stupid 'template systems' like what myBB has.

    The clear definition of "get the data" and then "output the data" always seemed more efficient; certainly more so than building the output buffer prematurely.

    It's really how I like to build programs; Get the data -- THEN show it. The get / show one line / get / show one line approach just makes things more complicated... especially if in the middle of the data you up and decide you want to output a HEADER.

    See why in my own CMS the theme_header() function starts out by "foreach $data['headers'] as $header" to call header() before any markup is started.

    I build all the page contents up into an array, then I output the results releasing the array values from memory with unset as I'm done with them. (since I prefer to do my own garbage collection as the output buffer builds... since I'm in mod_deflate from the start of output)

    Given that the files are clearly named, have a clear and logical directory structure, have prefixes to tell you what directory they might be contained in when back-referencing, and the output routines ONLY handle output and the data handling only handles data handling, I fail to see where you are getting the "here, there, everywhere" part.

    Quote Originally Posted by cheesedude View Post
    Write some code for us and I'll rewrite it using PHP's alternate syntax and with tons of comments. Then we'll do a little comparison and see how much faster yours is.
    AND AGAIN sure, the speed benefit might be miniscule, but it's there -- and if it means less code, simpler code, and more legible code, and less typing, WHERE'S THE PROBLEM?!?

    Quote Originally Posted by cheesedude View Post
    You want to see some slow code? Look at Wordpress 3.1. That thing has 76 separate files included on every pageview using the default template. Including a few things that are absolutely not needed.
    Now on that we can agree... turdpress is an unmitigated disaster under the hood; it's up to what? 400+ separate .php files when overall it has maybe 30 actual operations it performs? IF THAT? In a lot of ways you poke your head into the code, and it's like the people writing WP are deathly afraid of functions AND objects; almost more like a giant old-fashioned batch file or basic program written without even using GoSub. Actually, no, it's more like the old CHAIN command used in 8 and 16 bit memory spaces to let one program halt itself, unload it's code from memory while leaving it's variable data intact to load and run some other code.

    WP's idea of a function often seems to be to just make another file... then we wonder why it won the Pwnie for M4ss 0wnage a year or two ago.

    Quote Originally Posted by cheesedude View Post
    If you want to speed up a site, limit the number of files included. File access is magnitudes slower than executing code with or without comments and alternate syntax. PHP can execute thousands of lines of code in the time it takes to seek and open one file from the hard drive.
    ABSOLUTELY.

  16. #16
    SitePoint Guru aamonkey's Avatar
    Join Date
    Sep 2004
    Location
    kansas
    Posts
    953
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cheesedude View Post
    You want to see some slow code? Look at Wordpress 3.1. That thing has 76 separate files included on every pageview using the default template. Including a few things that are absolutely not needed.

    WordPress Support 77 Files Included Per Page View! Insane!

    If you want to speed up a site, limit the number of files included. File access is magnitudes slower than executing code with or without comments and alternate syntax. PHP can execute thousands of lines of code in the time it takes to seek and open one file from the hard drive.
    That actually seems like a low number of includes for something as big as WP.

    I don't know that the number of includes is as important as the size of the includes - for example, is including a hundred 10k files really slower than including one 1,000k file? I doubt it, and if you are trying to create a maintainable and organized application (instead of just something that runs as fast as possible) it would be ridiculous to even attempt that. Hell, I'm working on a relatively small application right now that has over 150 includes per page.

    At any rate, all these supposed performance issues can easily be fixed by installing APC.
    aaron-fisher.com - PHP articles and more

  17. #17
    SitePoint Guru bronze trophy
    Join Date
    Dec 2003
    Location
    Poland
    Posts
    925
    Mentioned
    7 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aamonkey View Post
    I don't know that the number of includes is as important as the size of the includes
    I'm afraid it really is.
    - for example, is including a hundred 10k files really slower than including one 1,000k file?
    I think it's a LOT slower. I haven't done tests myself but I've read of people gaining massive speed-ups by combining many small include files into one big chunk. PHP code parsing is lightning fast compared to file access. But as you said, with a good opcode cache the problem might not exist at all. It also depends on the efficiency of file caching by the OS - when I start a php site on localhost that has lots of includes I have to wait a few seconds hearing disk thrashing but after that the files are grabbed from a memory cache and the slowness almost disappears.

  18. #18
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by aamonkey View Post
    I don't know that the number of includes is as important as the size of the includes - for example, is including a hundred 10k files really slower than including one 1,000k file? I doubt it
    Depends on the transfer sizes actually; Though with the numbers you used -- yeah, unlikely...

    But if you're talking a hundred 100 byte files vs. a 10k file, then sure it might be enough of a difference -- 100 bytes is smaller than the sector size on most filesystems -- meaning that's a hundred separate sectors read as opposed to 20 sectors. (gets worse the larger the sector size -- you try that on a 2048 bytes per sector drive...)

    You also have the overhead of requests -- It's not just about the time to transfer the file, you have the head seek to the file system to find the filename's information and starting sector, the write to say the file is opened by someone, the seek to the position on the disk of the file ALL before you even start receiving or sending data...

    It's the same phenomenon as handshaking for HTTP or worse, FTP...

    Gah, FTP... Upload a hundred 10k files, then a single 1000K file... Guess which one runs about a hundred times faster. THANK BE that hard disk access isn't as inefficient. Apart from the sector round-up it's nowhere NEAR as bad.

    Happens on HTTP too -- each separate file request past the first few (depending on the number of simultaneous connects) can add real-world anywhere from 150ms to a full second and a half depending on ping-time, connection latency, distance from the server, etc... See why image recombination techniques are so good and using 20 separate .js files with a bloated library for two or three goofy animations are such total trash. (especially if requesting the file from a separate server given the delay on the second connect)

    Quote Originally Posted by aamonkey View Post
    At any rate, all these supposed performance issues can easily be fixed by installing APC.
    IF you allocate enough memory to it, IF the program you are trying to run is already in it's cache...

    Which is why it's not a 100% solution, but it's a damned fine one. In fact, the performance difference is so big it shows WHY calling a file from the disk and parsing it is where the bottleneck really is -- since when it does work those are removed from the equation.

    But that often comes down to are you on your own dedicated, a properly configured shared, or a dime a dozen stuff as many people as possible into a shared -- the further down the scale you go the less effective APC can be as the cache doesn't keep up with requests -- especially if the host isn't tuning it properly.

    Which is why as a developer it's often not a good idea to assume it's even going to be present/available/properly configured -- though praise the stars if it is.

  19. #19
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by cheesedude View Post
    If you want to speed up a site, limit the number of files included.
    Better option - use APC_CACHE.

    Conflating files needlessly makes for hard to manage code on a large project.

  20. #20
    SitePoint Wizard TheRedDevil's Avatar
    Join Date
    Sep 2004
    Location
    Norway
    Posts
    1,190
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by deathshadow60 View Post
    ... and I HATE to break it to you, but /FAIL/ hard. REALLY HARD.
    The idea of comments is to save time later on.

    You should write your code and comments in such a way than when you or anyone else needs to do any changes to the code a year from now. Then you will undertand what the code section does the second you read over it.

    With other words:
    Create proper laid out code, using variable names that is self explanitary proper spacing between the different commands/sections and of course comments on vital parts.


    That is what I prefer and so does any professional programmer. Having a piece of code that is self explanitary is worth A LOT more than the few ms of extra parsing time it costs.

    Heck, if speed were an issue you would never be programming using these languages in the first place...

    Quote Originally Posted by deathshadow60 View Post
    Of course, switching in and out of parse mode like some rubbish "scripting" language doesn't help... there's a reason I consider any php code that does <?php ?> more than once to be a steaming pile of garbage.
    Good for you!

    Though there is no reason why you should not be able to do that when programming in PHP. The template system we use (PHP) was actually created for this kind of use.

    Quote Originally Posted by deathshadow60 View Post
    All you have to do is look at the retard code example on the site for smarty -- no self respecting PHP developer would write GARBAGE like this:
    With the exception of the use of short tags, I personally feel the code in your first example was very good. Doing it this way has a big advantage of that your designers can easially update the template files with the new design without requiring any help from the programmers.

    You might also want to check up your statement with single quote vs double quote strings in PHP.

  21. #21
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by TheRedDevil View Post
    The idea of comments is to save time later on.

    You should write your code and comments in such a way than when you or anyone else needs to do any changes to the code a year from now. Then you will undertand what the code section does the second you read over it.
    Much of the time, comments are used because the code is not clear enough to explain what happens on its own.

    The best way to resolve that problem is not to add comments, but to refactor the code so that it becomes clear enough to explain what is happening.

    Can you tell that I've been reading the Clean Code book lately?
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  22. #22
    Non-Member bronze trophy
    Join Date
    Nov 2009
    Location
    Keene, NH
    Posts
    3,760
    Mentioned
    23 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    The best way to resolve that problem is not to add comments, but to refactor the code so that it becomes clear enough to explain what is happening.
    EXACTLY... and why I laugh whenever I hear the pathetic cop-outs of calling it "arbitrary formatting", "wastefully long variable or function names" or "rigid rules that aren't worth following" -- 27 years later and I'm STILL quoting the catholic nun who taught me to do something more than hobbyist level ASM/Basic on that subject -- "Vomiting up code any old way"

    Off Topic:

    (Funny that, a Jew taking coding lessons from a Catholic Nun. We get a protestant in there and we'd have a decent "walked into a bar" joke)


    It's also why I laugh and go "what are you thinking" whenever I see code like this:

    // Go and get our next record
    function ggi() {

    If it was named something proper, like say "getNextRecord" it wouldn't need the comment. Of course I REALLY love it when you point this out, and they say "oh, it's less to type" ... DUH... (because of course the comment is so much less text) It's why I'm alway pointing people at that article on the IBM linux dev site.

    Six ways to write more comprehensible code

    But you'll always have the people who ignore the better coding practices -- their loss... and their clients loss... and the loss of whatever poor slob has to clean up their mess. JHVH forbid things like indenting styles, naming conventions, style guides or any of the dozen other methods for writing cleaner, clearer easier to maintain code be followed.

    No, instead let's rely on tools to handle all that when computers aren't smart enough to do it; if they were we wouldn't need programmers. Many of such tools (like say pretty print) having been invented NOT to clean up the code of competent programmers, but as a means for competent programmers to have a baseline to clean up code written by the inept.

    Quote Originally Posted by paul_wilkins View Post
    Can you tell that I've been reading the Clean Code book lately?
    Can't say I've heard of that one, but it sounds good. Have to add that to my library.

  23. #23
    om nom nom nom Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,233
    Mentioned
    47 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by TomB
    If you're using vi.

    If you're using an IDE, the former will be easier to read/edit due to syntax highlighting, tag matching, code completion and HTML error checking. Not to mention the code you demonstrate would likely be surrounded by large chunks of HTML.
    You haven't used vim I take it? : )

    Quote Originally Posted by Crusty
    If I wanted to spend hours dicking around on the command line for functionality I've had with two or three clicks since windows 3.1,
    If you had spent hours dicking around on the command line, you'd have the functionality *typo! of the several clicks with one line. At least, that is what I propose : )

  24. #24
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,526
    Mentioned
    83 Post(s)
    Tagged
    3 Thread(s)
    Quote Originally Posted by Stomme poes View Post
    If you had spent hours dicking around on the command line, you'd have the functionalirt of the several clicks with one line. At least, that is what I propose : )
    The problem with trying to teach people to use a command line, is that it involves a much hated aspect of learning, and that is that they have to remember things.

    When using a mouse, they can be visually prompted along the way, which is a much lazier and slower way of doing things, but it's easier than that remembering stuff that you have to do on the command line.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  25. #25
    I solve practical problems. bronze trophy
    Michael Morris's Avatar
    Join Date
    Jan 2008
    Location
    Knoxville TN
    Posts
    2,011
    Mentioned
    56 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    Much of the time, comments are used because the code is not clear enough to explain what happens on its own.

    The best way to resolve that problem is not to add comments, but to refactor the code so that it becomes clear enough to explain what is happening.
    Yes, because every job has unlimited time with unlimited budgets.

    Refactoring is great when its an option - but in the real world with deadlines adding features to less than well thought out code then documentation by comments is often your only choice.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •