Skip to content

Reduce stack usage of ZSTD_buildCTable()#2522

Merged
terrelln merged 1 commit intofacebook:devfrom
terrelln:stack-reduction
Mar 5, 2021
Merged

Reduce stack usage of ZSTD_buildCTable()#2522
terrelln merged 1 commit intofacebook:devfrom
terrelln:stack-reduction

Conversation

@terrelln
Copy link
Contributor

@terrelln terrelln commented Mar 4, 2021

It is a stack high-point for some compression strategies and has an easy fix. This moves the normalized count into the entropy workspace.

assert(entropyWorkspaceSize >= FSE_BUILD_CTABLE_WORKSPACE_SIZE(MaxSeq, MaxFSELog));
FORWARD_IF_ERROR(FSE_normalizeCount(norm, tableLog, count, nbSeq_1, max, ZSTD_useLowProbCount(nbSeq_1)), "");
{ size_t const NCountSize = FSE_writeNCount(op, oend - op, norm, max, tableLog); /* overflow protected */
RETURN_ERROR_IF(entropyWorkspaceSize < sizeof(ZSTD_BuildCTableWksp), GENERIC, "wksp too small");
Copy link
Contributor

Choose a reason for hiding this comment

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

minor: if you believe that passing a too small entropyWorkspaceSize is something that should never happen if the code is correct, then using an assert() instead of a runtime error check would be appropriate here.

It is a stack high-point for some compression strategies and has an easy
fix. This moves the normalized count into the entropy workspace.
@terrelln terrelln merged commit e50f88c into facebook:dev Mar 5, 2021
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.

3 participants