From 8a05db230ec1a465bc6a5a8a459cf2214cc8e823 Mon Sep 17 00:00:00 2001 From: Jonas Jenwald Date: Thu, 9 Dec 2021 12:35:44 +0100 Subject: [PATCH] Further improve caching in `Catalog.getPageDict`, for `disableAutoFetch` mode (PR 8207 follow-up) PR 8207 added caching to improve the performance of `Catalog.getPageDict`, by not having to repeatedly fetch the same data and also reducing the asynchronicity of that method. However, because of *another* oversight on my part, we're only caching /Page references once we've found the correct page. As long as all pages are loaded *in order* this doesn't really matter (happens by default in the viewer), but when `disableAutoFetch` is used the pages may be fetched in a more random order (this patch reduces the asynchronicity of `Catalog.getPageDict` slightly in that case). --- src/core/catalog.js | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/src/core/catalog.js b/src/core/catalog.js index 5a6296557..31ca44f63 100644 --- a/src/core/catalog.js +++ b/src/core/catalog.js @@ -1117,13 +1117,14 @@ class Catalog { xref.fetchAsync(currentNode).then(function (obj) { if (isDict(obj, "Page") || (isDict(obj) && !obj.has("Kids"))) { + // Cache the Page reference, since it can *greatly* improve + // performance by reducing redundant lookups in long documents + // where all nodes are found at *one* level of the tree. + if (currentNode && !pageKidsCountCache.has(currentNode)) { + pageKidsCountCache.put(currentNode, 1); + } + if (pageIndex === currentPageIndex) { - // Cache the Page reference, since it can *greatly* improve - // performance by reducing redundant lookups in long documents - // where all nodes are found at *one* level of the tree. - if (currentNode && !pageKidsCountCache.has(currentNode)) { - pageKidsCountCache.put(currentNode, 1); - } capability.resolve([obj, currentNode]); } else { currentPageIndex++;