facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.12k stars 2.98k forks source link

Optimize PCRE for StaticStrings #5264

Open paulbiss opened 9 years ago

paulbiss commented 9 years ago

When we statically know the regex string passed to PCRE we can avoid a cache lookup on each call by burning the handle for the compiled regex into the TC.

wjywbs commented 9 years ago

Is it the right path to add a service request to compile the static string regex and write the handle in TC for the first time? The pcre caches for these regex can't be freed.

paulbiss commented 9 years ago

Well, it probably wouldn't be a service request, but the idea behind doing this with static strings is that they live forever anyway so it should be safe to burn the pcre handle in.

lexidor commented 11 months ago

HH\Lib\Regex\Pattern<T> literals are easy to spot in code.

re"/ab?cdc/"

In an ideal world, these would be compiled once and only once when this file is loaded (or even as a repo auth step, provided pcre handles can be serialized to disk). Hack can currently observe that re"" strings are just strings. A opaque value would be in order if changing this to a pcre handle expression.