Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add zstd compression #451

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

Rdataflow
Copy link

@constantinius this PR brings ZSTD support 😄
thanks for your review ...

Closes: #372

@Rdataflow Rdataflow force-pushed the feat--add_zstd branch 2 times, most recently from 516c9b9 to f80f727 Compare January 8, 2025 18:18

export default class ZstdDecoder extends BaseDecoder {
decodeBlock(buffer) {
return zstd.decode(new Uint8Array(buffer), 1000_000_000).buffer;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The second parameter is uncompressedSize, which is fixed here to 1 million. Is this significant? can we actually know it beforehand? What if the size is actually smaller/larger?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reading the source: if uninitialized (i.e: 0) the size should automatically be found out. Wouldn't that be a better solution?

I'm worried, that if the actual size is larger than the 1 million bytes buffer (which can easily be reached by 1024x1024 tile sizes) we might run into troubles.

Copy link
Author

@Rdataflow Rdataflow Jan 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@constantinius this value of 1 billion has been approximated using trial and error.
AFAICS 0 or omitting the param fails in the CI tests for some unknown reason.
however huge numbers make it pass w/o issues.
I couldn't observe any negative impact neither with 100 billion. (i.e. no mem limits hit)
for the full journey see this branch https://github.com/Rdataflow/geotiff.js/commits/ci-test/ and it's CI tests failing or passing
that's what drove us here... but maybe there exist even better ideas?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @Rdataflow

I investigated this. There is a function in zstd to determine the uncompressed size of a chunk. This is a property set in the chunk itself which is optional. When it is optional, zstd says to read the chunk in streaming mode. Otherwise proper decompression is not guaranteed. And this is something I'd like to avoid, since it may work on our test files, but not on random files used by people. So I'm against abusing the zstd library that way. Unfortunately, the zstd library we are currently using (and no other one I investigated) supports streaming decompression as it does not wrap the necessary functions of the wasm library.

I'm now trying to implement this streaming decoding into the zstd library. I'm thinking of incorporating that into the source code of geotiff.js directly, as it may be easier to handle.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @constantinius

Great you'll an even better way to implement zstd decompression 😃

just in case that becomes too heavy, I'll share my thoughts on alternative ways (up to you to decide and implement properly):

  • precalculate the uncompressed buffer size using the geotiff properties (tile size, bit depth, etc.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for ZSTD compressor
2 participants