From 5e3010b269cb09c8bd9672e1a6c3d104e80df890 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Sat, 11 May 2024 17:05:54 +0200 Subject: [PATCH] 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 isn't obviously enough to close the performance gap, but it *may* still be helpful. --- src/core/function.js | 5 ++++- src/display/api.js | 2 +- test/pdfs/pr5134.pdf.link | 1 + test/test_manifest.json | 9 +++++++++ 4 files changed, 15 insertions(+), 2 deletions(-) create mode 100644 test/pdfs/pr5134.pdf.link diff --git a/src/core/function.js b/src/core/function.js index 618eeee233572..10aae4cfc485f 100644 --- a/src/core/function.js +++ b/src/core/function.js @@ -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]; diff --git a/src/display/api.js b/src/display/api.js index 9c70a7c22cb2f..1f19d8ba1d18b 100644 --- a/src/display/api.js +++ b/src/display/api.js @@ -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 diff --git a/test/pdfs/pr5134.pdf.link b/test/pdfs/pr5134.pdf.link new file mode 100644 index 0000000000000..721dc2fdc0426 --- /dev/null +++ b/test/pdfs/pr5134.pdf.link @@ -0,0 +1 @@ +https://web.archive.org/web/20140211020222/http://www.coachusa.com/CoachUsaAssets/files/97/route45.pdf diff --git a/test/test_manifest.json b/test/test_manifest.json index 3b959e751c7d0..91de9f15f0eeb 100644 --- a/test/test_manifest.json +++ b/test/test_manifest.json @@ -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",