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

ZSTD_fast_noDict: Avoid Safety Check When Writing ip1 into Table #3129

Conversation

felixhandte
Copy link
Contributor

@felixhandte felixhandte commented May 10, 2022

This commit avoids checking whether a hashtable write is safe in two of the
three match-found paths in ZSTD_compressBlock_fast_noDict_generic. This pro-
duces a ~1% speed-up in compression.

This is a branch I've wanted to kill for a long time. It's very rarely useful.
Recent discussion with @embg brought this topic up again, and I finally had an
idea for how to do it (mostly).

A comment in the code describes why we can skip this check in the other two
paths (the repcode check and the first match check in the unrolled loop).

A downside is that in the new position where we make this check, we have not
yet computed mLength. We therefore have to avoid writing possibly dangerous
positions, rather than the old check which only avoids writing actually
dangerous positions. This leads to a miniscule loss in ratio (remember that
this scenario can only been triggered in very negative levels or under incomp-
ressibility acceleration).

This commit avoids checking whether a hashtable write is safe in two of the
three match-found paths in `ZSTD_compressBlock_fast_noDict_generic`. This pro-
duces a ~0.5% speed-up in compression.

A comment in the code describes why we can skip this check in the other two
paths (the repcode check and the first match check in the unrolled loop).

A downside is that in the new position where we make this check, we have not
yet computed `mLength`. We therefore have to avoid writing *possibly* dangerous
positions, rather than the old check which only avoids writing *actually*
dangerous positions. This leads to a miniscule loss in ratio (remember that
this scenario can only been triggered in very negative levels or under incomp-
ressibility acceleration).
@felixhandte felixhandte changed the title ZSTD_fast_noDict: Minimize Checks When Writing Hash Table for ip1 ZSTD_fast_noDict: Avoid Safety Check When Writing ip1 into Table May 10, 2022
lib/compress/zstd_fast.c Outdated Show resolved Hide resolved
Refactoring this way avoids the bad write in the case that `step > 4`, and
is a bit more straightforward. It also seems to perform better!
@felixhandte felixhandte force-pushed the zstd-fast-nodict-unconditional-ip1-table-write branch from 00abd35 to 1dd046a Compare May 11, 2022 16:38
@felixhandte felixhandte merged commit 8af64f4 into facebook:dev May 11, 2022
@nadavrot
Copy link

nadavrot commented Sep 7, 2022

Cool optimization @felixhandte !

@Cyan4973 Cyan4973 mentioned this pull request Feb 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants