Skip to content

Build the predefined sequence tables at compile time (Part of #118) - #123

Open
zcsizmadia wants to merge 1 commit into
mainfrom
small-frame-predefined-tables
Open

zcsizmadia wants to merge 1 commit into
mainfrom
small-frame-predefined-tables

Conversation

@zcsizmadia

Copy link
Copy Markdown
Owner

libzstd's ZSTD_buildCTable builds the predefined LL/OF/ML FSE tables
(set_basic) again for every block that uses them. On small frames most
blocks do (1 KiB frames: 60-90% of the table builds), and the table
build was a quarter of the time (C: FSE_buildCTable_wksp 27%).

FseCTable::predefined builds them at compile time (static
LL_PREDEFINED / OF_PREDEFINED / ML_PREDEFINED), and build_ctable copies
the used part (copy_used: the header, 1 << tableLog next states and
maxSymbolValue + 1 transforms, exactly what build writes; the predefined
distributions have no zero counts, whose delta_find_state build leaves
as it was). Same tables, same output.

Tests: predefined equals build on the random distributions of
build_matches_reference_spread (both spread paths), and copying each
predefined table over a fresh, an RLE and a larger table leaves exactly
what building it leaves. Workspace and portable test suites pass.

EPYC 7543 (bd-au1-jz001g3v), 16 lanes, 3 rounds, 2 binary copies of each
side interleaved, medians; all 12 Silesia files; output sizes identical
in every case. Speed branch/main (geomean over the files):

chunk L-5 L-1 L1 L3 L5 L9 L16 L19
1 KiB 1.426 1.222 1.084 1.053 1.021 1.014 1.007 1.006
4 KiB 1.055 1.017 1.009 1.006 1.005 1.003 1.002 1.002
16 KiB 1.012 1.005 1.001 1.004 1.001 1.003 1.002 1.003
64 KiB 1.001 1.002 1.003 1.005 1.002 1.002 1.003 1.001
full 1.002 1.002 1.000 1.000 0.998 0.997

Full files rerun with fresh copies: one branch copy ran sao L-1 at
0.78x with the same instruction count as the others (copy placement);
fresh copies of the same file ran at main's speed. nci L5/L9 full
(0.986) have identical instruction counts, cycles within the copy
spread. perf stat, mozilla L-1 1 KiB: instructions 21.59G -> 15.45G,
cycles 6.65G -> 5.07G, 588 -> 785 MiB/s (zrip L-1: 770 at ratio 1.743;
zstd-native 1.762). Against C libzstd 1.6.0 at the same level: 1.25x
on 1 KiB frames (was 1.14x), 1.11x on full files.

libzstd's ZSTD_buildCTable builds the predefined LL/OF/ML FSE tables
(set_basic) again for every block that uses them. On small frames most
blocks do (1 KiB frames: 60-90% of the table builds), and the table
build was a quarter of the time (C: FSE_buildCTable_wksp 27%).

FseCTable::predefined builds them at compile time (static
LL_PREDEFINED / OF_PREDEFINED / ML_PREDEFINED), and build_ctable copies
the used part (copy_used: the header, 1 << tableLog next states and
maxSymbolValue + 1 transforms, exactly what build writes; the predefined
distributions have no zero counts, whose delta_find_state build leaves
as it was). Same tables, same output.

Tests: predefined equals build on the random distributions of
build_matches_reference_spread (both spread paths), and copying each
predefined table over a fresh, an RLE and a larger table leaves exactly
what building it leaves. Workspace and portable test suites pass.

EPYC 7543 (bd-au1-jz001g3v), 16 lanes, 3 rounds, 2 binary copies of each
side interleaved, medians; all 12 Silesia files; output sizes identical
in every case. Speed branch/main (geomean over the files):

  chunk    L-5    L-1    L1     L3     L5     L9     L16    L19
  1 KiB    1.426  1.222  1.084  1.053  1.021  1.014  1.007  1.006
  4 KiB    1.055  1.017  1.009  1.006  1.005  1.003  1.002  1.002
  16 KiB   1.012  1.005  1.001  1.004  1.001  1.003  1.002  1.003
  64 KiB   1.001  1.002  1.003  1.005  1.002  1.002  1.003  1.001
  full     1.002  1.002  1.000  1.000  0.998  0.997

Full files rerun with fresh copies: one branch copy ran sao L-1 at
0.78x with the same instruction count as the others (copy placement);
fresh copies of the same file ran at main's speed. nci L5/L9 full
(0.986) have identical instruction counts, cycles within the copy
spread. perf stat, mozilla L-1 1 KiB: instructions 21.59G -> 15.45G,
cycles 6.65G -> 5.07G, 588 -> 785 MiB/s (zrip L-1: 770 at ratio 1.743;
zstd-native 1.762). Against C libzstd 1.6.0 at the same level: 1.25x
on 1 KiB frames (was 1.14x), 1.11x on full files.

This branch has not been deployed

No deployments
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.

1 participant