Add some simple naive caching to the tiff file#31
Conversation
| | _ -> failwith "Unsupported compression" | ||
| in | ||
|
|
||
| t.strip_cache <- |
There was a problem hiding this comment.
I'm not exactly sure what this gets compiled to, but I think it would be better to put the matching statement outside of the assignment operation. IDK if the compiler is smart enough to recognise that if t.caching_policy = NoCachingis a no-op.
| Lzw.decode raw_strip_buffer uncompressed_buffer; | ||
| uncompressed_buffer | ||
| | _ -> failwith "Unsupported compression" | ||
| match List.assoc_opt strip t.strip_cache with |
There was a problem hiding this comment.
I wonder if we're better off using something with O(1) lookup here. It probably doesn't matter too much but we do incur a bit of a hit the first time we load something in and have the caching policy set (as we have to loop through the entire strip_cache for every strip).
| end | ||
|
|
||
| type t = { header : header; ifd : Ifd.t } | ||
| (* I imagine one day we will also have `Some of int` as an option here *) |
There was a problem hiding this comment.
What will that do? Only cache n strips?
I do wonder if we should not make the ro more sophisticated here so the TIFF library doesn't have to deal with this. A user could already do something very similar themselves using the file_offset as the cache key?
|
Great points in the review @patricoferris - thanks. Re the placement:
We could make windowing a yirgacheffe problem, and just expose strips/tiles at the TIFF library, then you solve the second of those issues. |
|
I feel convinced, one thought that this stirred (and this is my own ignorance showing) but how does windowing work in terms of LZW compression? Do you need to start decompressing from the start of a strip even if you are going to start somewhere in the middle of the strip because the user supplied some offset? I think it would be good to expose strips and tiles at some point as an "expert" interface, but I would also like users to be able to work with the tiff library directly so let's keep this and add in the caching layer :)) Sorry for the conflicts, do you want me to take care of those? |
No description provided.