[php-src] Issue #9487: Consider optimizing regular expressions at compile time?

From: Date: Mon, 05 Sep 2022 16:50:39 +0000
Subject: [php-src] Issue #9487: Consider optimizing regular expressions at compile time?
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-242366@lists.php.net to get a copy of this message
Issue: https://github.com/php/php-src/issues/9487 Author: Ocramius ### Description While looking at generated opcodes for some PHP source, I noticed that regular expressions are always sent to ext-pcre via INIT_FCALL+SEND_VAL: ```php <?php return \preg_match('/a/', $var); ``` ``` Finding entry points Branch analysis from position: 0 1 jumps found. (Code = 62) Position 1 = -2 filename: /in/VAGlk function name: (null) number of ops: 6 compiled vars: !0 = $var line #* E I O op fetch ext return operands ------------------------------------------------------------------------------------- 3 0 E > INIT_FCALL 'preg_match' 1 SEND_VAL '%2Fa%2F' 2 SEND_VAR !0 3 DO_ICALL $1 4 > RETURN $1 5* > RETURN 1 ``` I was wondering if, when: 1. The function is known upfront (being a pcre_*() one) 2. The regex is known upfront (via constant propagation) ... it could be possible to: 1. Compile the regex upfront 2. Optimize the regex upfront 3. Cache the results in opcache, perhaps as a specialized opcode? Note: I don't have any idea of how heavy this is, or whether JIT already takes care of this.

« previous php.bugs (#242366) next »