Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider isolate group-wide weak cache for RegExp #51228

Closed
mkustermann opened this issue Feb 2, 2023 · 0 comments
Closed

Consider isolate group-wide weak cache for RegExp #51228

mkustermann opened this issue Feb 2, 2023 · 0 comments
Assignees
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

Comments

@mkustermann
Copy link
Member

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

@mkustermann mkustermann added area-vm Use area-vm for VM related issues, including code coverage, and the AOT and JIT backends. type-performance Issue relates to performance or code size type-enhancement A request for a change that isn't a bug labels Feb 2, 2023
@rmacnak-google rmacnak-google self-assigned this Feb 2, 2023
copybara-service bot pushed a commit that referenced this issue Feb 6, 2023
…aching 256 RegExp per isolate.

TEST=ci
Bug: #51228
Change-Id: Ie2869585ae847ea154460122d7ec5af81ef7697c
Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/280521
Commit-Queue: Ryan Macnak <rmacnak@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Alexander Aprelev <aam@google.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

2 participants