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

DecodeAll without checks #556

Closed
WojciechMula opened this issue Apr 14, 2022 · 3 comments
Closed

DecodeAll without checks #556

WojciechMula opened this issue Apr 14, 2022 · 3 comments

Comments

@WojciechMula
Copy link
Contributor

Background: we may decode the same compressed data several times. Although it's possible the data is broken, then in such a case we won't try to decode it again.

I'm wondering if it would be possible to introduce a variant of decoding, where all sanity checks are not performed (like: if literals are big enough, if match length is within a range, and so on, so forth),

A client code would use it like this:

for i := range inputs {
  // 
  if firstDecode(inputs[i]) {
    decoded, err := decoder.DecodeAll(inputs[i], nil)
    if err {
      ...
    }
  } else {
    decoded := decoder.DecodeAllValid(inputs[i])
  }
}
@klauspost
Copy link
Owner

(afk - on mobile, so short answer)

I honestly don't think there will be much difference. Branches are predictable and there aren't really that many checks.

The important part is allocations, which go away on the second uses.

I don't really want potentially crashing code to be available. So a "probably no". Maybe if enabled by a build tag.

@WojciechMula
Copy link
Contributor Author

Thank you for the answer. I fully understand you don't want an unsafe code.

@WojciechMula
Copy link
Contributor Author

I have just checked the version without checks --- no significant changes were noticed in benchmarks. The biggest speedup is 1.05x, and some quite significant regressions

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

No branches or pull requests

2 participants