[
https://issues.apache.org/jira/browse/TIKA-4796?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18099707#comment-18099707
]
ASF GitHub Bot commented on TIKA-4796:
--------------------------------------
gsingers opened a new pull request, #2968:
URL: https://github.com/apache/tika/pull/2968
## Summary
- `MagicDetector` recompiled its `Pattern` on every regex match even though
the pattern bytes and case-insensitivity flag are fixed at construction time;
now compiled once in the constructor and reused (`Pattern` is immutable,
`Matcher` is still created per call, so the regex path stays thread-safe).
- Adds direct coverage for the regex branch of `matches(byte[])`, which
`MagicMatch.eval` exercises for every magic in `tika-mimetypes.xml` but which
was previously only tested indirectly, plus repeated-call and concurrent-use
tests over a shared detector instance.
- CHANGES.txt entry added.
## Test plan
- [x] `./mvnw clean test -pl :tika-core -Dtest=MagicDetectorTest`
- [x] `./mvnw clean install`
https://claude.ai/code/session_01Pp6TVDKF7ztw7SS7hwwuFd
> Caching of MagicDetector pattern compilations
> ---------------------------------------------
>
> Key: TIKA-4796
> URL: https://issues.apache.org/jira/browse/TIKA-4796
> Project: Tika
> Issue Type: Improvement
> Reporter: Grant Ingersoll
> Priority: Minor
>
> I've been doing some profiling of Tika as part of a broader focus on a
> document extraction pipeline and one of the areas that shows up more than
> expected and appears to be an easy fix is the
> {code:java}
> Pattern p = Pattern.compile(new String(this.pattern, UTF_8), flags);{code}
> line in `matchesBuffer` (trunk/main) and the `detect` method in the 3.x line.
>
> The fix is to compile the pattern in the initialization. Patch/fix coming
> shortly.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)