Skip to content

Commit

Permalink
Use fuzzy-matching to improve cache hit rates with PostScriptEvaluator
Browse files Browse the repository at this point in the history
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 isn't obviously enough to close the performance gap, but it *may* still be helpful.
  • Loading branch information
Snuffleupagus committed May 11, 2024
1 parent b676540 commit 5e3010b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 2 deletions.
5 changes: 4 additions & 1 deletion src/core/function.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,7 +456,10 @@ class PDFFunction {
for (i = 0; i < numInputs; i++) {
value = src[srcOffset + i];
input[i] = value;
key += value + "_";
// Fuzzy-match to increase the cache hit rate which helps improve
// performance, at the expense of absolute rendering quality.
// (At least in the test-suite the differences are imperceivable).
key += Math.round(value * 1e8) / 1e8 + "_";
}

const cachedValue = cache[key];
Expand Down
2 changes: 1 addition & 1 deletion src/display/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ function getDocument(src) {
Number.isInteger(src.maxImageSize) && src.maxImageSize > -1
? src.maxImageSize
: -1;
const isEvalSupported = src.isEvalSupported !== false;
const isEvalSupported = false; // src.isEvalSupported !== false;
const isOffscreenCanvasSupported =
typeof src.isOffscreenCanvasSupported === "boolean"
? src.isOffscreenCanvasSupported
Expand Down
1 change: 1 addition & 0 deletions test/pdfs/pr5134.pdf.link
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
https://web.archive.org/web/20140211020222/http://www.coachusa.com/CoachUsaAssets/files/97/route45.pdf
9 changes: 9 additions & 0 deletions test/test_manifest.json
Original file line number Diff line number Diff line change
Expand Up @@ -2221,6 +2221,15 @@
"lastPage": 1,
"type": "eq"
},
{
"id": "pr5134",
"file": "pdfs/pr5134.pdf",
"md5": "6a701a163472e071a2519348b55cbac1",
"rounds": 1,
"link": true,
"firstPage": 2,
"type": "eq"
},
{
"id": "issue5599",
"file": "pdfs/issue5599.pdf",
Expand Down

0 comments on commit 5e3010b

Please sign in to comment.