Skip to content

Commit b354b3a

Browse files
committed
Use fuzzy-matching to improve cache hit rates with PostScriptEvaluator
This improves performance, without any noticeable regressions when running `gulp browsertest --noChrome` locally on Windows. Testing the new `pr5134` test-case locally in the viewer: - With the `master` branch and `isEvalSupported = true`, page 2 renders in approx. 350 milliseconds. - With the `master` branch and `isEvalSupported = false`, page 2 renders in approx. 1550 milliseconds. - With this patch, which forces `isEvalSupported = false`, page 2 renders in approx. 990 milliseconds. Hence this obviously isn't enough to close the performance gap, but it *may* still be helpful.
1 parent b676540 commit b354b3a

File tree

4 files changed

+15
-2
lines changed

4 files changed

+15
-2
lines changed

src/core/function.js

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -456,7 +456,10 @@ class PDFFunction {
456456
for (i = 0; i < numInputs; i++) {
457457
value = src[srcOffset + i];
458458
input[i] = value;
459-
key += value + "_";
459+
// Fuzzy-match to increase the cache hit rate which helps improve
460+
// performance, at the expense of absolute rendering quality.
461+
// (At least in the test-suite the differences are imperceivable.)
462+
key += Math.round(value * 1e8) / 1e8 + "_";
460463
}
461464

462465
const cachedValue = cache[key];

src/display/api.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ function getDocument(src) {
279279
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
280280
? src.maxImageSize
281281
: -1;
282-
const isEvalSupported = src.isEvalSupported !== false;
282+
const isEvalSupported = false; // src.isEvalSupported !== false;
283283
const isOffscreenCanvasSupported =
284284
typeof src.isOffscreenCanvasSupported === "boolean"
285285
? src.isOffscreenCanvasSupported

test/pdfs/pr5134.pdf.link

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
https://web.archive.org/web/20140211020222/http://www.coachusa.com/CoachUsaAssets/files/97/route45.pdf

test/test_manifest.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2221,6 +2221,15 @@
22212221
"lastPage": 1,
22222222
"type": "eq"
22232223
},
2224+
{
2225+
"id": "pr5134",
2226+
"file": "pdfs/pr5134.pdf",
2227+
"md5": "6a701a163472e071a2519348b55cbac1",
2228+
"rounds": 1,
2229+
"link": true,
2230+
"firstPage": 2,
2231+
"type": "eq"
2232+
},
22242233
{
22252234
"id": "issue5599",
22262235
"file": "pdfs/issue5599.pdf",

0 commit comments

Comments
 (0)