Skip to content

Commit 8ea24dc

Browse files
Add details about optimizer passes (#4858)
And expand on what the unsafe optimizations do and when they could potentially be applied. Co-authored-by: Gina Peter Banyard <girgias@php.net>
1 parent 34c7b33 commit 8ea24dc

File tree

1 file changed

+162
-3
lines changed

1 file changed

+162
-3
lines changed

reference/opcache/ini.xml

Lines changed: 162 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -590,10 +590,169 @@
590590
<listitem>
591591
<simpara>
592592
A bitmask that controls which optimisation passes are executed.
593-
The default is to apply all safe optimizations.
594-
Changing the default is mostly useful for debugging/developing the optimizer
595-
(see also <link linkend="ini.opcache.opt_debug_level">opcache.opt_debug_level</link>).
593+
The default value is <literal>0x7FFEBFFF</literal>, which enables all
594+
safe optimizations. Disabling optimizations or enabling unsafe optimizations
595+
is mostly useful for debugging/developing the optimizer.
596596
</simpara>
597+
<simpara>
598+
Each bit in the bitmask enables a specific optimization pass:
599+
</simpara>
600+
<table>
601+
<title>Optimization Pass Bitmask</title>
602+
<tgroup cols="4">
603+
<thead>
604+
<row>
605+
<entry>Bit</entry>
606+
<entry>Pass Name</entry>
607+
<entry>&Description;</entry>
608+
<entry>Default</entry>
609+
</row>
610+
</thead>
611+
<tbody>
612+
<row>
613+
<entry>0</entry>
614+
<entry>PASS_1</entry>
615+
<entry>Simple peephole optimizations</entry>
616+
<entry>On</entry>
617+
</row>
618+
<row>
619+
<entry>1</entry>
620+
<entry>PASS_2</entry>
621+
<entry>Unused (got merged into PASS_1)</entry>
622+
<entry>On</entry>
623+
</row>
624+
<row>
625+
<entry>2</entry>
626+
<entry>PASS_3</entry>
627+
<entry>Simple jump optimization</entry>
628+
<entry>On</entry>
629+
</row>
630+
<row>
631+
<entry>3</entry>
632+
<entry>PASS_4</entry>
633+
<entry>Call optimization</entry>
634+
<entry>On</entry>
635+
</row>
636+
<row>
637+
<entry>4</entry>
638+
<entry>PASS_5</entry>
639+
<entry>Control Flow Graph based optimization</entry>
640+
<entry>On</entry>
641+
</row>
642+
<row>
643+
<entry>5</entry>
644+
<entry>PASS_6</entry>
645+
<entry>Data Flow Analysis based optimization</entry>
646+
<entry>On</entry>
647+
</row>
648+
<row>
649+
<entry>6</entry>
650+
<entry>PASS_7</entry>
651+
<entry>Whether call graph should be used for SSA-based optimizations</entry>
652+
<entry>On</entry>
653+
</row>
654+
<row>
655+
<entry>7</entry>
656+
<entry>PASS_8</entry>
657+
<entry>Sparse conditional constant propagation</entry>
658+
<entry>On</entry>
659+
</row>
660+
<row>
661+
<entry>8</entry>
662+
<entry>PASS_9</entry>
663+
<entry>Temporary variable optimization</entry>
664+
<entry>On</entry>
665+
</row>
666+
<row>
667+
<entry>9</entry>
668+
<entry>PASS_10</entry>
669+
<entry>Removal of NOP opcodes</entry>
670+
<entry>On</entry>
671+
</row>
672+
<row>
673+
<entry>10</entry>
674+
<entry>PASS_11</entry>
675+
<entry>Literal compaction</entry>
676+
<entry>On</entry>
677+
</row>
678+
<row>
679+
<entry>11</entry>
680+
<entry>PASS_12</entry>
681+
<entry>Pre-compute call stack size</entry>
682+
<entry>On</entry>
683+
</row>
684+
<row>
685+
<entry>12</entry>
686+
<entry>PASS_13</entry>
687+
<entry>Unused variable removal</entry>
688+
<entry>On</entry>
689+
</row>
690+
<row>
691+
<entry>13</entry>
692+
<entry>PASS_14</entry>
693+
<entry>Dead code elimination</entry>
694+
<entry>On</entry>
695+
</row>
696+
<row>
697+
<entry>14</entry>
698+
<entry>PASS_15</entry>
699+
<entry>Collect and substitute constant declarations (unsafe)</entry>
700+
<entry><emphasis>Off</emphasis></entry>
701+
</row>
702+
<row>
703+
<entry>15</entry>
704+
<entry>PASS_16</entry>
705+
<entry>Trivial function inlining (part of call optimization)</entry>
706+
<entry>On</entry>
707+
</row>
708+
<row>
709+
<entry>16</entry>
710+
<entry>(Flag)</entry>
711+
<entry>Ignore possibility of operator overloading (unsafe)</entry>
712+
<entry><emphasis>Off</emphasis></entry>
713+
</row>
714+
</tbody>
715+
</tgroup>
716+
</table>
717+
<note>
718+
<title>Safe vs Unsafe Optimizations</title>
719+
<simpara>
720+
<emphasis>Safe optimizations</emphasis> (enabled by default) preserve the exact
721+
behavior of PHP code while improving performance. They include dead code elimination,
722+
constant folding, and jump optimization.
723+
</simpara>
724+
<simpara>
725+
<emphasis>Unsafe optimizations</emphasis> (disabled by default) may alter behavior
726+
in edge cases:
727+
</simpara>
728+
<itemizedlist>
729+
<listitem>
730+
<simpara>
731+
<emphasis>Bit 14</emphasis>: Collecting constants. Constants are substituted
732+
at compile-time, ignoring runtime declaration order:
733+
</simpara>
734+
<informalexample>
735+
<programlisting role="php">
736+
<![CDATA[
737+
<?php
738+
echo getA(); // Outputs: "hello" instead of throwing an Error
739+
const A = "hello";
740+
function getA() { return A; }
741+
]]>
742+
</programlisting>
743+
</informalexample>
744+
</listitem>
745+
<listitem>
746+
<simpara>
747+
<emphasis>Bit 16</emphasis>: Ignoring operator overloading.
748+
Unsafe when using classes with <literal>do_operation</literal>
749+
(e.g. <link linkend="book.gmp">GMP</link>,
750+
<link linkend="book.bc">BCMath</link>) in arithmetic operations.
751+
With type declarations, the optimizer can apply the same optimizations safely.
752+
</simpara>
753+
</listitem>
754+
</itemizedlist>
755+
</note>
597756
</listitem>
598757
</varlistentry>
599758
<varlistentry xml:id="ini.opcache.inherited-hack">

0 commit comments

Comments
 (0)