Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Feat: Introduce ScopedPatternFilterFactory for Managed, Thread-Safe Filtering#287

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Open
YuyuZha0 wants to merge5 commits intogliwka:main
base:main
Choose a base branch
Loading
fromYuyuZha0:thread-safe-pattern-filter

Conversation

@YuyuZha0
Copy link

Key Motivation

The existingPatternFilter class is effective for single-threaded use but has two critical limitations in concurrent environments:

  1. It is not thread-safe.
  2. It is expensive to instantiate, as eachnew PatternFilter() triggers a full Hyperscan database compilation.

This forces consumers to implement their own complex and error-prone pooling orThreadLocal management to use Hyperscan filtering safely and efficiently in multi-threaded applications like web servers.

This PR introducesScopedPatternFilterFactory as a high-level, managed solution that solves these problems out of the box.

Key Differences & Improvements

The newScopedPatternFilterFactory supersedes the manualPatternFilter approach by providing:

  • Thread-Safety by Design: The factory manages a unique, isolatedScopedPatternFilter instance for each thread, eliminating the need for external synchronization.

  • High Performance via Caching: The expensive database compilation is performed only once per thread. Subsequent requests for a filter on the same thread reuse the already-compiled instance, drastically improving performance.

  • Simplified and Safer API: Users interact with a single factory instance and obtain a filter viatry-with-resources (var filter = factory.get()). This returns a proxy that prevents accidental closure of the shared, thread-local resource.

  • Automatic Resource Cleanup: It introduces a robust,PhantomReference-based mechanism to automatically release native resources for threads that have terminated, preventing memory leaks in dynamic environments.

@YuyuZha0
Copy link
Author

@gliwka Could you please help me review this PR? Thank you!

@gliwka
Copy link
Owner

Thank you for your contribution. I'll take a look over the weekend.

Sign up for freeto join this conversation on GitHub. Already have an account?Sign in to comment

Reviewers

No reviews

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

2 participants

@YuyuZha0@gliwka

[8]ページ先頭

©2009-2025 Movatter.jp