Skip to content

Keep the buffer zero past its bytes - #38

Merged
srijs merged 1 commit into
mainfrom
zeroed-tail
Sep 27, 2026
Merged

srijs merged 1 commit into
mainfrom
zeroed-tail

Conversation

@srijs

@srijs srijs commented Sep 27, 2026

Copy link
Copy Markdown
Owner

finalize wrote the marker after the buffered tail, then zeroed the rest of the block with a fill of variable length, just before the block was read to be compressed. The buffer now stays zero past its bytes instead: it starts that way, update only appends to it, and a buffer that has been compressed is zeroed whole before the next tail goes in. Padding is then the marker and the length alone.

On an Apple M4, interleaved against main (5 rounds, criterion medians), every way of hashing a short message is faster, the streaming Hasher as much as the one-shot:

  one update and finalize             1-64 B   -5.3%
  object-shaped, header and content   1-64 B   -5.2%
  one-shot digest()                   1-64 B   -5.2%
  any of the three                    65-512 B -0.5% to -1.3%
  16 KiB throughput                            -0.1%

finalize wrote the marker after the buffered tail, then zeroed the rest
of the block with a fill of variable length, just before the block was
read to be compressed. The buffer now stays zero past its bytes
instead: it starts that way, update only appends to it, and a buffer
that has been compressed is zeroed whole before the next tail goes in.
Padding is then the marker and the length alone.

On an Apple M4, interleaved against main (5 rounds, criterion medians),
every way of hashing a short message is faster, the streaming Hasher
as much as the one-shot:

  one update and finalize             1-64 B   -5.3%
  object-shaped, header and content   1-64 B   -5.2%
  one-shot digest()                   1-64 B   -5.2%
  any of the three                    65-512 B -0.5% to -1.3%
  16 KiB throughput                            -0.1%
@srijs
srijs merged commit c23fbf9 into main Sep 27, 2026
20 checks passed
@srijs
srijs deleted the zeroed-tail branch September 27, 2026 20:37
@srijs srijs mentioned this pull request Sep 28, 2026
srijs added a commit that referenced this pull request Sep 28, 2026
sha1dc 0.1.5 recompresses on the SHA-1 instructions, which makes it 2–4%
faster than 0.1.4 on large inputs on every machine with them: about 2% on
the Apple M4, Graviton4, Sapphire Rapids and Zen, and 4% on Ice Lake.
Detection now costs 16% to 22% of throughput, down from 18% to 23%.

Notable changes:

- A block that trips the filter is recompressed on the ARMv8 SHA-1
  instructions or SHA-NI, from the boundary at step 60 or 64 in both
  directions, where it used to take the portable compression (#36).
- The hasher keeps its buffer out of what the compression receives, and
  tracks the buffered bytes by the total length alone (#37). The buffer
  stays zero past its bytes, so finalizing writes only the 0x80 and the
  length (#38).
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