Skip to content

Build Not yet confirmed elsewhere1 publisher 3 min read Published

A 41% Throughput Win That Was Algebra, Not Assembly

A Go secret scanner sped up its Shannon entropy stage by rewriting the formula and precomputing a 4 KiB table, with no CGo, no unsafe, and no heap allocations.

The Engineer · Build desk

How we use AI Send a correction

Illustration accompanying A 41% Throughput Win That Was Algebra, Not Assembly
Generated illustration

What happened

  • Khaled Hani reports that rewriting the Shannon entropy equation and precomputing a small lookup table produced a 41.4% increase in benchmark throughput in the Crenox Git secret scanner.
  • The optimized implementation maintained 0 heap allocations per operation.
  • The post states the solution was not CGo, assembly, or unsafe code; it was algebra.
  • Crenox runs as a pre-commit hook on a developer's workstation before every commit, so the scanner has to do a lot of work without adding noticeable latency to the development workflow.
  • Crenox uses a three-tier detection pipeline: Tier 1 Aho-Corasick pattern matching across 125+ known provider patterns; Tier 2 Shannon entropy analysis for high-randomness candidates such as generic tokens, hashes and credentials; Tier 3 context-aware verification to reduce false positives from test fixtures, mock data and non-secret identifiers.

Why it matters

Khaled Hani, writing about the Crenox Git secret scanner, reports that the entropy stage of its detection pipeline got 41.4% more throughput after the Shannon entropy formula was algebraically restructured and the expensive part moved into a precomputed lookup table [1][2]. The interesting part is what was not used: the post is explicit that the fix was not CGo, assembly, or unsafe [3], which is the usual destination when someone decides a hot loop is out of headroom.

The constraint is real. Crenox runs as a pre-commit hook on a developer workstation before every commit, so the scanner has to finish its work without adding noticeable latency to the commit [4]. Detection runs in three tiers: Aho-Corasick matching over 125-plus known provider patterns, then Shannon entropy analysis on high-randomness candidates such as generic tokens, hashes and credentials, then context-aware verification to suppress false positives from test fixtures and mock data [5]. Tier 2 is called hundreds of thousands of times, according to the author, which is what makes per-call floating point arithmetic worth attacking [6].

The naive implementation builds a 256-entry frequency table, then for each non-zero count computes p = count/n and accumulates -p*log2(p): a float conversion, a division, a math.Log2 call and more arithmetic per distinct byte value [7][8]. Substituting p = c/n and applying the logarithm identity gives H = log2(n) - (1/n) * sum(c*log2(c)), because every byte contributes exactly once to the frequency table so the counts sum to n [9]. Mathematically identical, per the post [10], but the loop body is now c*log2(c) on an integer with a bounded range [11].

Bounded is the operative word. If the input is at most 512 bytes, no individual byte frequency can exceed 512, so every value of c*log2(c) the loop will ever need can be computed once at init into a [513]float64 array, sized 513 rather than 512 because Go arrays are zero-indexed and a run of 512 identical bytes needs index 512 [12][13][14]. That table is 4,104 bytes, roughly 4.01 KiB [15]. The fast path then does one math.Log2, on n, instead of one per distinct byte present, which in the naive version can be up to 256 [17]. Inputs over 512 bytes fall back to the original calculation [16]. Allocations stayed at zero per operation [2].

Read the 41.4% figure the right way. A 41.4% throughput increase corresponds to about 29% less time per call, which is a solid but not exotic result for removing a transcendental function from a loop [18]. It also only applies below the 512-byte threshold; anything larger takes the fallback and gets nothing [16].

What to watch: whether real scanner inputs actually sit under 512 bytes in practice, because a line-oriented scanner will and a blob-oriented one will not; whether the fallback path becomes the new hot path on large files, which would argue for a segmented or chunked table rather than a bigger one; and whether the two code paths agree closely enough at the entropy thresholds that drive Tier 3, since a candidate sitting on the boundary can be classified differently by two routines that are equivalent on paper. The transferable lesson is the ordering: rewrite the expression, bound the domain, precompute, and only then consider the escape hatches.

Clarity's read

What the record supports and how the coverage leans. The claims behind it follow.

Reality

Evidence64
Adoption14
Hype gap+14
Incentives62
Confidence57
Why these scores

Claim ledger

Ranked by verification strength, evidence, and original report placement.

  1. [1]

    Khaled Hani reports that rewriting the Shannon entropy equation and precomputing a small lookup table produced a 41.4% increase in benchmark throughput in the Crenox Git secret scanner.

    Reported Supported Source: Khaled Hani, dev.toView cited source
  2. [2]

    The optimized implementation maintained 0 heap allocations per operation.

    Reported Supported Source: Khaled Hani, dev.toView cited source
  3. [3]

    The post states the solution was not CGo, assembly, or unsafe code; it was algebra.

    Reported Supported Source: Khaled Hani, dev.toView cited source

Get this ledger inside ChatGPT. Ask about any of our stories and the answer brings its figure, each claim’s verdict and the sources. Free, no account.

Add to ChatGPTAdd to Claude

Sources

1 independent publisher whose own reporting we read for this story.

  1. dev.to

    1 article · August 16, 2026

    How We Increased Shannon Entropy Throughput in Go by 41% Using a Lookup Table.

Share your take

Let Clarity write the post for you.

Signed-in readers get a short post drafted on this story in the register they choose — narrative, analytical, or a direct position — editable to the last word before it goes anywhere. The share buttons at the top of this story work without an account.

Topics and entities

Follow any of these and your For You feed starts watching them — no settings page required.

Topics

Entities

Loading related stories