Consider isolate group-wide weak cache for RegExp #51228
Labels
area-vm
Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends.
type-enhancement
A request for a change that isn't a bug
type-performance
Issue relates to performance or code size
When creating
RegExp
objects, the factory constructor looks up in a cache and may return an existing regexp if available, otherwise creates a new_RegExp
object, puts it into the cache and returns it.The cache itself is a custom hashmap implementation with hard-coded maximum size of 256. So that means we hold on to regexp objects even if we don't need them anymore, but we also may fail to re-use existing regexp objects if the cache is exhausted. Furthermore the cache isn't shared across isolates, and may therefore lead to multiple regexps for the same pattern.
We could piggy-back on the recently introduced weak arrays: Insert RegExp objects into a weak array based hash set. New regexp constructor invocations can look up in the weak set for existence of an existing entry and re-use. It could be shared across isolates since regexp's themselves can be shared. (somewhat analogous to weak string canonicalization table).
(It would also be nice to remove yet-another custom set/map implementation)
/cc @aam @rmacnak-google
The text was updated successfully, but these errors were encountered: