echo "This is a constant string";
?>
echo "This is an interpolated $string";
?>
INIT STRING ~0
ADD_STRING ~0 ~0 'This'
ADD_STRING ~0 ~0 ' '
ADD_STRING ~0 ~0 'is'
ADD_STRING ~0 ~0 ' '
ADD_STRING ~0 ~0 'an'
ADD_STRING ~0 ~0 ' '
ADD_STRING ~0 ~0 'interpolated'
ADD_STRING ~0 ~0 ' '
ADD_VAR ~0 ~0 !0
ECHO ~0
Where !0 represents the compiled variable named $string. Looking at these opcodes: INIT_STRING allocates an IS_STRING variable of one byte (to hold the terminating NULL). Then it's realloc'd to five bytes by the first ADD_STRING ('This' plus the terminating NULL). Next it's realloc'd to six bytes in order to add a space, then again to eight bytes for 'is', then nine to add a space, and so on until the temporary string has the contents of the interpolated variable copied into its contents before being used by the echo statement and finally discarded. Now let's rewrite that line to avoid interpolation and use concatenation instead:
Does this come out to a simple, single opcode? Nope, because the rules necessary to catch a heredoc's end token demand the same careful examination as double-quoted variable substitution and you wind up (in this case) with SEVENTY-EIGHT opcodes! One INIT_STRING, 76 ADD_STRINGs. and a final ECHO. That means a malloc, 76 reallocs, and a free which will be executed every time that code snippet comes along. Even the original contents take up more memory because they're stored in 76 distinct zval/IS_STRING structures.
Why does this happen? Because there are about a dozen ways that a variable can be hidden inside an interpolated string. Similarly, when looking for a heredoc end-token, the token can be an arbitrary length, containing any of the label characters, and may or may not sit on a line by itself. Put simply, it's too difficult to encompass in one regular expression.
If you're using APC, you'll find just such an optimizer built in, but not enabled by default. To turn it on, you'll need to set apc.optimization=on in your php.ini. In addition to stitching these run-on opcodes back together, it'll also add run-time speed-ups like pre-resolving persistent constants to their actual values, folding static scalar expressions (like 1 + 1) to their fixed results (e.g. 2), and simpler stuff like avoiding the use of JMP when the target is the next opcode, or boolean casts when the original expression is known to be a boolean value. (It should be noted that these speed-ups also break some of the runtime-manipulation features of runkit, but that was stuff you....probably should have been doing anyway)
Can't use an optimizer because your webhost doesn't know how to set php.ini options? You can still avoid 90% of the INIT_STRING/ADD_STRING dilema by simply using single quotes and concatenation (or commas when dealing with echo statements). It's a simple trick and one which shouldn't harm maintainability too much, but on a large, complicated script, you just might see an extra request or two per second.
I found this answer by typing the question into my search box.
2007-08-10 09:36:46
·
answer #1
·
answered by Yarnlady_needsyarn 7
·
0⤊
0⤋
a sprint bit string is going right into a pub an sits down. The bartender says you will possibly desire to bypass away we dont serve string here. The string is going out to the line and asks a guy to tie him in a knot. the guy does it yet as he ties the knot the ends of the string become frayed. The string says thats ok and walks back into the pub a sits down. The bartender says, are not you that piece of string I kicked out of here till now. The string says no i'm a frayed knot.
2016-11-11 21:38:59
·
answer #2
·
answered by ? 4
·
0⤊
0⤋
How is 'How long is a piece of string?’ a pseudo-question? It might be vague, but every explanation always is, and it seems absurd to say that vague answers are not truth-evaluable according to non-vague criteria. IE: if you were to specify the answer in centimetres by default, but refuse to do it in millimetres or micrometres, you should not be faulted, and your answer would be satisfying. If we can't even answer those questions, then no mundane questions can be answered either (unless you were to specify the appropriate conditions of an answer within the question). =}
2007-08-09 12:01:49
·
answer #3
·
answered by Becka 4
·
0⤊
2⤋
It all depends how long you want it, just curious what are you doing with the string?.
2007-08-09 12:09:13
·
answer #4
·
answered by painterlady 3
·
0⤊
0⤋
Is this a metric or imperial piece of string?
If metric,then yard for metre it has to be longer.
2007-08-09 12:01:18
·
answer #5
·
answered by firebobby 7
·
0⤊
0⤋
4 inches
That's my string theory
2007-08-09 12:01:35
·
answer #6
·
answered by Kev E 5
·
1⤊
0⤋
No, How Long is a China man
2007-08-09 12:02:11
·
answer #7
·
answered by Anonymous
·
1⤊
1⤋
Normaly a little bit shorter than the job you need it for.
2007-08-09 16:09:03
·
answer #8
·
answered by LEANNE 2
·
0⤊
0⤋
It's whats left of the part it was cut from.
2007-08-09 12:09:23
·
answer #9
·
answered by Honeypai 4
·
0⤊
0⤋
Its as long as you want it to be.
2007-08-09 12:04:57
·
answer #10
·
answered by Diminished 3
·
0⤊
0⤋