LibGfx: Decode Mellor_ACTITC_10.pdf faster [3/N]#26250
LibGfx: Decode Mellor_ACTITC_10.pdf faster [3/N]#26250nico merged 2 commits intoSerenityOS:masterfrom
Conversation
| if (!inputs.uses_huffman_encoding || inputs.uses_refinement_or_aggregate_coding) { | ||
| auto bitmap = TRY(read_symbol_bitmap(symbol_width, height_class_height)); | ||
| new_symbols.append(Symbol::create(move(bitmap))); | ||
| new_symbols.append(Symbol::create(bitmap->subbitmap(IntRect(0, 0, bitmap->width(), bitmap->height())))); |
There was a problem hiding this comment.
As the two types are not compatible, it forces a few of these conversions.
These are the only non-mechanical changes in the decoder.
There was a problem hiding this comment.
Maybe BilevelImage should have a rect() method, similar to Gfx::Bitmap. That'd make this here slightly less awkward.
(No action needed.)
There was a problem hiding this comment.
Or a as_subbitmap method?
8abcad1 to
8277d84
Compare
nico
left a comment
There was a problem hiding this comment.
Very nice!
The commit message grammar-o is the only real comment.
For non-CCITT jbig2s, the additional rect bounds are a teeny tiny slowdown, but it's probably in the measurement noise. (261.0 ms ± 3.7 ms -> 258.9 ms ± 2.8 ms for big_image.jpg converted to jbig2 and then hyperfine 'Build/lagom/bin/image --no-output big_image.jbig2')
| if (!inputs.uses_huffman_encoding || inputs.uses_refinement_or_aggregate_coding) { | ||
| auto bitmap = TRY(read_symbol_bitmap(symbol_width, height_class_height)); | ||
| new_symbols.append(Symbol::create(move(bitmap))); | ||
| new_symbols.append(Symbol::create(bitmap->subbitmap(IntRect(0, 0, bitmap->width(), bitmap->height())))); |
There was a problem hiding this comment.
Maybe BilevelImage should have a rect() method, similar to Gfx::Bitmap. That'd make this here slightly less awkward.
(No action needed.)
This type stores a pointer to an upstream `BilevelImage` and a rectangle, corresponding to the dimensions of the sub-bitmap. It is introduced to avoid the copies that were made in `BilevelImage::subbitmap`. When using this test case: ``` BuildLagom/bin/pdf --render out.png PDF/Mellor_ACTITC_10.pdf --page 4 ``` The number of calls to `subbitmap` is ~25000, and none of the resulting sub-bitmaps are modified. So making shallow copies gives a nice performance improvement: according to valgrind, this makes the time spent in `BilevelImage::subbitmap` drop from 26% to 0.03%.
8277d84 to
f26ef2a
Compare
Symbol was a RefCounted wrapper around BilevelImage. As of SerenityOS#26250, BilevelImage is refcounted itself, and it moved the loader to BilevelSubImage which can cheaply be copied. Just use that directly. No behavior change.
Symbol was a RefCounted wrapper around BilevelImage. As of SerenityOS#26250, BilevelImage is refcounted itself, and it moved the loader to BilevelSubImage which can cheaply be copied. Just use that directly. No behavior change.
Symbol was a RefCounted wrapper around BilevelImage. As of SerenityOS#26250, BilevelImage is refcounted itself, and it moved the loader to BilevelSubImage which can cheaply be copied. Just use that directly. No behavior change.
Symbol was a RefCounted wrapper around BilevelImage. As of SerenityOS#26250, BilevelImage is refcounted itself, and it moved the loader to BilevelSubImage which can cheaply be copied. Just use that directly. No behavior change.
Symbol was a RefCounted wrapper around BilevelImage. As of #26250, BilevelImage is refcounted itself, and it moved the loader to BilevelSubImage which can cheaply be copied. Just use that directly. No behavior change.
Related to #26082
Before:
After: