Skip to content

CCITT decoder is slow for wide images #26082

@nico

Description

@nico

Get this file: https://library.sciencemadness.org/library/books/Mellor_ACTITC_10.pdf

Then:

% time Build/lagom/bin/pdf --render out.png Mellor_ACTITC_10.pdf --page 4 
Build/lagom/bin/pdf --render out.png Mellor_ACTITC_10.pdf --page 4  1.33s user 0.02s system 99% cpu 1.361 total

Running it under instruments shows that basically all time is spent decoding CCITT data:

Image

Almost all of the time is spent in take_first(), likely the call on line 494. ReferenceLine is a Vector<Change>, so take_first is O(n). Adding -dump-contents to the invocation shows that the image is 3074 pixels wide, and this take_last probably makes something O(n^2), which for 3000 starts getting slow.

Maybe using a ReadonlySpan if possible, or a CircularQueue or something could be an easy way to improve a lot here.

@LucasChollet

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions