PCRE2: allocate jit stack/match data once per thread#15955
Closed
ysbaddaden wants to merge 6 commits intocrystal-lang:masterfrom
Closed
PCRE2: allocate jit stack/match data once per thread#15955ysbaddaden wants to merge 6 commits intocrystal-lang:masterfrom
ysbaddaden wants to merge 6 commits intocrystal-lang:masterfrom
Conversation
straight-shoota
approved these changes
Jul 3, 2025
Collaborator
Author
|
Grmbl. macOS CI is acting up again 😡 |
Member
|
macOS seems still broken. Any idea what's happening? Can someone with a mac check if this reproduces locally (and optionally investigate)? |
Collaborator
Author
|
Sigh. I'll have to start a tmate-action to see what's happening 😞 |
It seems to avoid a segfault on Darwin on CI, which may just be related to the old LLVM 11 version that we still use in shell.nix that's only use on the macOS CI woprkflow.
Collaborator
Author
|
Hum, it still segfaults on x86_64-darwin but not on aarch64-darwin 🤨 |
This reverts commit b85d9be.
Trying to set the struct's `@key` in the `#initialize` methods leads to a segfault when the struct will be set as a global (for example a class variable).
Collaborator
Author
|
Progress on macOS: I tried everything I could think of, and it eventually worked correctly on x86_64-darwin, but the process will segfault whenever we unwind the stack (e.g. we raise an exception). On the other hand, |
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Allocates the PCRE2 jit stack scratch space and match data once per thread, instead of once per thread and per regular expression.
Uses the new internal
Thread::Local(T)type to store the allocations, along with a destructor to make sure that the allocations will be freed when a thread terminates — no strong dependency, the library won't be linked if PCRE2 isn't used.Bonuses:
Removes the last usage of
Crystal::ThreadLocalValueoutside ofIO::Evented(used by libevent and wasi).Creating and accessing the jit stack and match data no longer needs to go through a Mutex (contention) or a Hash (complexity), we just go through a libc fun call.
Regular expressions shall thus be faster, at the expense of some memory, maybe (large allocated match data).
Follow up to #15616.
Obsoletes #15395 (where there are more details)