mirror of
https://github.com/mozilla/pdf.js.git
synced 2025-04-25 09:38:06 +02:00
Add local caching of TilingPatterns in PartialEvaluator.getOperatorList
(issue 2765 and 8473)
In practice it's not uncommon for PDF documents to re-use the same TilingPatterns more than once, and parsing them is essentially equal to parsing of a (small) page since a `getOperatorList` call is required. By caching the internal TilingPattern representation we can thus avoid having to re-parse the same data over and over, and there's also *less* asynchronous parsing required for repeated TilingPatterns. Initially I had intended to include (standard) benchmark results with this patch, however it's not entirely clear that this is actually necessary here given the preliminary results. When testing this manually in the development viewer, using `pdfBug=Stats`, the following (approximate) reduction in rendering times were observed when comparing `master` against this patch: - http://pubs.usgs.gov/sim/3067/pdf/sim3067sheet-2.pdf (from issue 2765): `6800 ms` -> `4100 ms`. -1046131/stepped.pdf
(from issue 8473): `54000 ms` -> `13000 ms` -1046130/proof.pdf
(from issue 8473): `5900 ms` -> `2500 ms` As always, whenever you're dealing with documents which are "slow", there's usually a certain level of subjectivity involved with regards to what's deemed acceptable performance. Hence it's not clear to me that we want to regard any of the referenced issues as fixed, however the improvements are significant enough to warrant caching of TilingPatterns in my opinion.
This commit is contained in:
parent
99a2302d88
commit
30e8d5dea1
3 changed files with 127 additions and 69 deletions
|
@ -133,6 +133,29 @@ class LocalGStateCache extends BaseLocalCache {
|
|||
}
|
||||
}
|
||||
|
||||
class LocalTilingPatternCache extends BaseLocalCache {
|
||||
set(name, ref = null, data) {
|
||||
if (!name) {
|
||||
throw new Error(
|
||||
'LocalTilingPatternCache.set - expected "name" argument.'
|
||||
);
|
||||
}
|
||||
if (ref) {
|
||||
if (this._imageCache.has(ref)) {
|
||||
return;
|
||||
}
|
||||
this._nameRefMap.set(name, ref);
|
||||
this._imageCache.put(ref, data);
|
||||
return;
|
||||
}
|
||||
// name
|
||||
if (this._imageMap.has(name)) {
|
||||
return;
|
||||
}
|
||||
this._imageMap.set(name, data);
|
||||
}
|
||||
}
|
||||
|
||||
class GlobalImageCache {
|
||||
static get NUM_PAGES_THRESHOLD() {
|
||||
return shadow(this, "NUM_PAGES_THRESHOLD", 2);
|
||||
|
@ -231,5 +254,6 @@ export {
|
|||
LocalColorSpaceCache,
|
||||
LocalFunctionCache,
|
||||
LocalGStateCache,
|
||||
LocalTilingPatternCache,
|
||||
GlobalImageCache,
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue