Commit 6717e03
perf: jpeg2000 valid_file implementation, much faster than trying to open (#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]>1 parent 8f315bd commit 6717e03
1 file changed
+30
-20
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
80 | 80 | | |
81 | 81 | | |
82 | 82 | | |
| 83 | + | |
83 | 84 | | |
84 | 85 | | |
85 | 86 | | |
| |||
97 | 98 | | |
98 | 99 | | |
99 | 100 | | |
100 | | - | |
| 101 | + | |
| 102 | + | |
101 | 103 | | |
102 | 104 | | |
103 | 105 | | |
| |||
208 | 210 | | |
209 | 211 | | |
210 | 212 | | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
211 | 218 | | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
212 | 226 | | |
213 | 227 | | |
214 | 228 | | |
| |||
409 | 423 | | |
410 | 424 | | |
411 | 425 | | |
412 | | - | |
413 | 426 | | |
414 | | - | |
| 427 | + | |
415 | 428 | | |
416 | | - | |
417 | | - | |
418 | | - | |
419 | | - | |
420 | | - | |
421 | | - | |
422 | | - | |
423 | | - | |
424 | | - | |
425 | | - | |
426 | | - | |
427 | | - | |
| 429 | + | |
| 430 | + | |
| 431 | + | |
428 | 432 | | |
429 | 433 | | |
| 434 | + | |
| 435 | + | |
| 436 | + | |
| 437 | + | |
| 438 | + | |
| 439 | + | |
430 | 440 | | |
431 | 441 | | |
432 | 442 | | |
433 | 443 | | |
434 | | - | |
435 | | - | |
436 | | - | |
| 444 | + | |
| 445 | + | |
| 446 | + | |
437 | 447 | | |
438 | 448 | | |
439 | 449 | | |
440 | | - | |
441 | | - | |
| 450 | + | |
| 451 | + | |
442 | 452 | | |
443 | 453 | | |
444 | 454 | | |
| |||
0 commit comments