-
Notifications
You must be signed in to change notification settings - Fork 186
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
Rdataflow
wants to merge
2
commits into
geotiffjs:master
Choose a base branch
from
Rdataflow:feat--add_zstd
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
import { ZSTDDecoder } from 'zstddec'; | ||
import BaseDecoder from './basedecoder.js'; | ||
|
||
export const zstd = new ZSTDDecoder(); | ||
|
||
export default class ZstdDecoder extends BaseDecoder { | ||
decodeBlock(buffer) { | ||
return zstd.decode(new Uint8Array(buffer), 1000_000_000).buffer; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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?There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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):