Skip to content

The package hash is the builtin, and take twill 1.12.0 - #5

Merged
martin-k-m merged 1 commit into
mainfrom
perf/pkghash-is-the-builtin
Sep 12, 2026
Merged

martin-k-m merged 1 commit into
mainfrom
perf/pkghash-is-the-builtin

Conversation

@martin-k-m

Copy link
Copy Markdown
Collaborator

What was wrong. src/pkghash.tw hashed a vendored tree through std/hash, SHA-256 run one 32-bit word at a time in the interpreter, about 100 kB/s on this machine. docs/needs.md entry 13 asked for a builtin and recorded std/hash as the answer. The README's install block also said twill 1.7.0 was enough and pointed at the v1.8.0 asset, which was already stale against the 1.9.0 pin.

What changed. hash_tree calls twill 1.11's sha256 builtin, the same digest as std/hash and held to it in twill by a test over every message length from 0 to 70 bytes. The std/hash import in pkghash.tw is gone. tests/sha256_test.tw checks the seven published vectors through sha256, which is now the function spool calls, and keeps std/hash for padded_len. README, needs entry 13 and the CHANGELOG say what is true now; the pin, the README install block and CI move to 1.12.0.

How verified. On twill 1.12.0 built from twill/twill main: twill test tests gives 6 passed, 0 failed; twill check passes on every .tw file; the em dash gate is clean. Timed with mono_ns on one machine: builtin 16 MB in 6.5 ms; std/hash 65536 bytes in 0.69 s. The million-a vector was not added: the builtin hashes it in 0.3 ms but s.repeat takes 21 s to build it, and the comment in the test says so.

🤖 Generated with Claude Code

docs/needs.md entry 13 asked for a sha256 builtin and settled on std/hash,
which is SHA-256 interpreted one 32-bit word at a time. twill 1.11 has the
builtin, held to std/hash by a test in twill over every message length from 0
to 70 bytes. hash_tree calls it now. Measured with mono_ns: 16 MB in 6.5 ms,
where std/hash took 0.69 s for 65536 bytes on the same machine.

tests/sha256_test.tw checks the published vectors through sha256, which is
the function spool calls, and keeps std/hash for padded_len. The README's
install block still said 1.7.0 was enough and pointed at the v1.8.0 asset,
which was stale against the 1.9.0 pin and is wrong against this one. The
pin, the README and CI move to 1.12.0.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@martin-k-m
martin-k-m merged commit 7282e86 into main Sep 12, 2026
2 checks passed
@martin-k-m
martin-k-m deleted the perf/pkghash-is-the-builtin branch September 12, 2026 16:18
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