diff options
author | Ken Sharp <ken.sharp@artifex.com> | 2022-02-21 15:16:10 +0000 |
---|---|---|
committer | Ken Sharp <ken.sharp@artifex.com> | 2022-02-21 15:40:25 +0000 |
commit | e377bbb5e36d5e9ea861640a7ce9f7e56e91733e (patch) | |
tree | 54f2c6a30a36f8d70960f70904a4f981261ccfc4 /pdf/pdf_func.c | |
parent | 68c5ebd4e4963ee5328d65c1e7a245cb10dac0df (diff) | |
download | ghostpdl-e377bbb5e36d5e9ea861640a7ce9f7e56e91733e.tar.gz |
GhostPDF - Performance enhancement don't cache type 3 sub-functions
The test file /tests_private/pdf/pdf_1.7_ATS/WWTW61EC_file.pdf exhibits
a marked performance problem on page 2.
This is because it has many shadings, each of which use one of a small
number of functions. We cache the functions, as with all objects, so
would expect these to be processed efficiently. However, the functions
are type 3 stitching functions and each one has 255 sub-functions.
This means that as we process the function array we eject every cached
item (and then some of the sub-functions), which means that we lose the
benefit of the cache.
This commit adds 'nocache' options to the derefrencing code, and new
options in array and dictionary handling to retrieve objects without
adding them to the cache. We only actually use the nocaching array
routine, but it seems worth having a matching dictionary version
available.
This improves the performance of the file in question by a factor > 10.
Diffstat (limited to 'pdf/pdf_func.c')
-rw-r--r-- | pdf/pdf_func.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/pdf/pdf_func.c b/pdf/pdf_func.c index 949b800d7..9537152ed 100644 --- a/pdf/pdf_func.c +++ b/pdf/pdf_func.c @@ -563,7 +563,18 @@ pdfi_build_function_3(pdf_context *ctx, gs_function_params_t * mnDR, for (i = 0; i < params.k; ++i) { pdf_obj * rsubfn = NULL; - code = pdfi_array_get(ctx, (pdf_array *)Functions, (int64_t)i, &rsubfn); + /* This is basically hacky. The test file /tests_private/pdf/pdf_1.7_ATS/WWTW61EC_file.pdf + * has a number of shadings on page 2. Although there are numerous shadings, they each use one + * of four functions. However, these functions are themselves type 3 functions with 255 + * sub-functions. Because our cache only has 200 entries (at this moment), this overfills + * the cache, ejecting all the cached objects (and then some). Which means that we throw + * out any previous shadings or functions, meaning that on every use we have to reread them. This is, + * obviously, slow. So in the hope that reuse of *sub_functions* is unlikely, we choose to + * read the subfunction without caching. This means the main shadings, and the functions, + * remain cached so we can reuse them saving an enormous amount of time. If we ever find a file + * which significantly reuses sub-functions we may need to revisit this. + */ + code = pdfi_array_get_nocache(ctx, (pdf_array *)Functions, (int64_t)i, &rsubfn); if (code < 0) goto function_3_error; |