Closed GerHobbelt closed 2 years ago
See https://bugs.ghostscript.com/show_bug.cgi?id=703870#c3 :: turns out it's my own damn fault. 😰
Issue resolved in bleeding edge mupdf submodule.
Culprit commit: https://github.com/GerHobbelt/mupdf/commit/165d4088305fefc4880acf6f5535254cd8b83d5c
The goal of this work was to find out if (and how) I could get MuPDF to render any pages within a given time frame and, without barfing a hairball via fz_throw(), if such is not possible, to at least render something, even though it will be 'corrupt'. The goal here is to first check this and make it possible, so I will know where to patch the code properly later on when I want this behaviour: interruptable and/or time-limited renders which give a warning without crashing through a C# .NET interface layer thanks to setjmp/longjmp in fz_try/fz_throw/fz_catch.
To that end, this HACKY CODE HACK has been done:
do_not_edit
flag in the major CPU guzzling routine fz_run_display_list() @ >98% CPU.if (prev_progress + 100 <= progress && !do_not_draw)
clipped
flag, while it looked nicee on the surface, immediately started to bomb the code with fz_throw() exceptions due to failing checks, so that was/is a no-go.do_not_draw
variable as a flag to turn off fz_fill_path() and fz_stroke_path() entry, the next step was to tweak:
the do_not_edit
flag was turned in a counter and a simple modulo code (as shown in this commit) was to ensure at least some of the elements were rendered, so you'ld see something. Knowing this was b0rked (not matching source PDF any more) but showing anything quickly is better than nothing given the aforementioned goal.do_not_draw
flag/counter to almost anywhere in the code
dnd_modulus
so as to deliver a modulus of zero in the end, as it turned out that now the grouping code was the big consumer anyhow.Conclusion:
Also do realize that the ranking of these costly calls is such that in that level 1,2,3 list, nothing shows up on the radar when you haven't killed the topmost still-active item, so focusing on improving the PDF parser performance would be utterly ludicrous.
This entire drama started at 30+ minutes (instrumented debug build, aborted!!!) and was brought down to ~ 10 seconds in the end, while luck would have it that the disabled / skipped code did not very noticably damage the rendered output of THIS PDF. Of course, YMMV. Those groupings and blending modes aren't in there for no reason!
This commit represents the end state of this story / hack.
P.S.: I found out by code inspection that there's a cookie->abort flag, which might be useful for my second goal: interruptable => abortable page renderings! However, do note that fiddling with that flag will cause an error to be fz_throw()n -- flip that flag in mupdf while running the app in the debugger and you're get an alert box and blank screen!
This HACKY code change is [yes, commit message is clipped off, regrettably]
https://bugs.ghostscript.com/show_bug.cgi?id=703870