-
Notifications
You must be signed in to change notification settings - Fork 963
TIKA-4745 -- efficiency improvements #2878
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 our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
d5ef09b
TIKA-4745 -- efficiency improvements
tballison 6730ade
TIKA-4745 -- further efficiency improvements
tballison 0621874
TIKA-4745 -- further efficiency improvements
tballison bb57967
TIKA-4745 -- further efficiency improvements, respond to copilot
tballison b199a69
TIKA-4745 -- respond to copilot
tballison c324793
TIKA-4745 -- clean up module boundaries and respond to copilot
tballison 7dd27bd
TIKA-4745 -- tiny cleanup
tballison File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
65 changes: 65 additions & 0 deletions
65
tika-core/src/main/java/org/apache/tika/detect/EncodingProbeCache.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.tika.detect; | ||
|
|
||
| /** | ||
| * Caches the raw encoding-detection probe (the leading bytes read for detection) | ||
| * so that multiple detectors in a chain do not each re-read and re-tag-strip the | ||
| * same bytes. For example a statistical detector and a downstream meta detector | ||
| * that re-reads the bytes for arbitration can share one probe. | ||
| * <p> | ||
| * An instance is held by {@link EncodingDetectorContext}, so it inherits that | ||
| * context's per-detection lifecycle: created fresh per detection and discarded | ||
| * with the context immediately afterwards. That matters because a | ||
| * {@link org.apache.tika.parser.ParseContext} flows on into recursive | ||
| * (attachment/embedded) parsing — a probe must never outlive the single detection | ||
| * it was read for. | ||
| * <p> | ||
| * Not thread-safe: a single detection runs its detectors sequentially on one | ||
| * thread. The cache is keyed by the probe parameters — {@link #get} returns the | ||
| * cached probe only when both {@code contentTarget} and {@code rawCap} match what | ||
| * it was stored with, so a detector that wants a differently-sized probe | ||
| * transparently reads (and caches) its own. | ||
| * <p> | ||
| * The cached array is shared read-only state; callers must not mutate it in place. | ||
| */ | ||
| public class EncodingProbeCache { | ||
|
|
||
| private byte[] probe; | ||
| private int contentTarget = -1; | ||
| private int rawCap = -1; | ||
|
|
||
| /** | ||
| * @return the cached probe if one was stored with the same {@code contentTarget} and | ||
| * {@code rawCap}; otherwise {@code null} | ||
| */ | ||
| public byte[] get(int contentTarget, int rawCap) { | ||
| if (probe != null && this.contentTarget == contentTarget && this.rawCap == rawCap) { | ||
| return probe; | ||
| } | ||
| return null; | ||
| } | ||
|
|
||
| /** | ||
| * Stores the probe bytes read with the given parameters. | ||
| */ | ||
| public void put(byte[] probe, int contentTarget, int rawCap) { | ||
| this.probe = probe; | ||
| this.contentTarget = contentTarget; | ||
| this.rawCap = rawCap; | ||
| } | ||
| } |
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
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
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
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
Binary file modified
BIN
-305 KB
(69%)
...coding-detector-mojibuster/src/main/resources/org/apache/tika/ml/chardetect/nb-bigram.bin
Binary file not shown.
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.