Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
perf: jpeg2000 valid_file implementation, much faster than trying to …
…open (AcademySoftwareFoundation#4548) Primary cost of detecting whether a given file is valid jpeg2000 file is the thread pool initialization and shutdown that `Jpeg2000Input::open` does (the actual thread pool part is inside OpenJpeg code). So add a dedicated `valid_file()` implementation that only needs to check 12 bytes of the header. While at it, I changed already existing `isJp2File()` to `is_jp2_header()` to better match naming conventions used elsewhere, and instead of trying to handle both little and big endian cases by manual repetition of two sets of magic integers, let's do just byte comparisons with `memcmp` instead. On my PC (Ryzen 5950X, SSD, Windows VS2022), doing `ImageInput::create()` on 1138 files where they are not images at all (so OIIO in turns tries all the input plugins on them): - Before: **3.4 seconds** spent in `Jpeg2000Input::open` (1.9s `opj_thread_pool_create`, 1.3s `opj_thread_pool_destroy`) - After: **33 milliseconds** spent in `Jpeg2000Input::valid_file` No new tests. I checked behavior on the official Jpeg2000 conformance data set (https://github.com/uclouvain/openjpeg-data/tree/master/input/conformance), seems to work. Signed-off-by: Aras Pranckevicius <[email protected]>
- Loading branch information