Skip to content

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Jul 3, 2025

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::ThreadLocalValue outside of IO::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)

@ysbaddaden
Copy link
Contributor Author

Grmbl. macOS CI is acting up again 😡

@straight-shoota straight-shoota marked this pull request as draft July 18, 2025 12:06
@straight-shoota straight-shoota removed this from the 1.18.0 milestone Jul 18, 2025
@ysbaddaden ysbaddaden marked this pull request as ready for review July 18, 2025 12:17
@straight-shoota
Copy link
Member

straight-shoota commented Jul 19, 2025

macOS seems still broken. Any idea what's happening?

Can someone with a mac check if this reproduces locally (and optionally investigate)?

@straight-shoota straight-shoota marked this pull request as draft July 19, 2025 17:23
@ysbaddaden
Copy link
Contributor Author

Sigh. I'll have to start a tmate-action to see what's happening 😞

ysbaddaden and others added 2 commits July 23, 2025 00:01
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.
@ysbaddaden
Copy link
Contributor Author

Hum, it still segfaults on x86_64-darwin but not on aarch64-darwin 🤨

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).
@ysbaddaden
Copy link
Contributor Author

ysbaddaden commented Jul 23, 2025

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, aarch64-darwin seems to be working correctly. At least with LLVM 20.

@ysbaddaden ysbaddaden closed this Sep 27, 2025
@ysbaddaden ysbaddaden deleted the refactor/pcre2-use-thread-local branch September 27, 2025 18:09
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants