PCRE2: use thread local for jit stack and match data#16175
PCRE2: use thread local for jit stack and match data#16175straight-shoota merged 5 commits intocrystal-lang:masterfrom
Conversation
This is a simple abstraction over the `ThreadLocal` annotation (for quick access) that also injects a reference into `Thread.current` to keep the value visible to the GC (that can't scan `ThreadLocal` values). There is no support for destructors. When needed just use a class with a finalizer: when the Thread is collected the thread local value will also be collected, which will run the finalizer.
Refactors the PCRE2 allocations for the jit stack scratch space and match data to once per thread, instead of once per thread per Regex. No more `Crystal::ThreadLocalValue` that involves a mutex to protect a global hash (contention and complexity). Regular expressions may run a bit faster, especially in a MT environment. Relies on the `thread_local` macro and class wrappers for the raw PCRE2 pointers with a finalizer method that will free the allocations when we don't need them anymore (i.e. the thread has stopped). There are still no strong dependency: the external libpcre2 won't be linked if the program doesn't use regular expressions.
|
We might want to wait for #16194, then revert the last commit before merge (we don't bother with backward compatibility with the interpreter, yet). |
|
I'd rather not bother with that. We can merge this with the wrapper and then simplify after #16194. Backwards compatibility of the interpreter may not be as important. But it's very inconvenient for testing purposes if stdlib code doesn't work with interpreter from the latest release. It means you need to rebuild the compiler with changes from master. |
|
Well, that's the case right now with |
See #15395 for details.
Depends on #16173.