Skip to main content
AboutWorkExperienceLogHireResume
PreviousPraxisNextPageForge
HomeProjectsAboutExperienceLogHireContactResumeGitHubLinkedIn
© 2026 Bhargav Kr Nath
All projects
Merged·apple/coreai-models #524·Nov 18, 2026ML inference performance, numerical stability

Sampling without sorting the vocabulary.

Top-p and min-p sampling in Apple’s open-source coreai-models sorted the whole vocabulary on every generated token. I replaced the sort with a bounded candidate window and a bucketed mass scan, kept every sampling behaviour, and fixed two floating-point failures that review turned up. Merged as pull request #524.

An independent open-source contribution. I am not an Apple employee, and this is not an endorsement by Apple.

Repository
apple/coreai-models
Pull request
#524, closes issue #499
My role
Author of the change and its tests
Size
2 files, +387 −11
Read the merged pull request
155x
min-p sampler call, 30.6 to 0.20 ms
MacBook Air M1, vocab 262,144, release build
12–14x
top-p sampler call, 31 to 2.2–2.5 ms
flat and Gaussian bulk, same harness before and after
262,144
Vocabulary size it is tested at
Gemma 4’s vocabulary; the final tests run at this size
11
New test functions, 23 cases
against a full-sort reference, plus +inf and fp16 coverage

Speedups are for the sampler call alone, measured on one MacBook Air M1 with synthetic logits. They are not end-to-end inference speedups.

The 30-second version

Merged pull requestIssue #499
Problem
Apple's coreai-models sorted the entire 262,144-token vocabulary on every generated token to apply top-p or min-p, a step the issue reporter measured at about 17 ms per token on Gemma 4 E2B, close to the forward pass.
What I built
A logit-space cutoff, a ln V + 18 candidate window, and a 2,048-bucket mass walk that locates the nucleus without sorting, then an exact scan over a small sorted prefix. Review added Double accumulation and fixes for +inf logits.
Result
Sampler call on a MacBook Air M1 at vocab 262,144: top-p 31 to 2.2 to 2.5 ms (12 to 14x), min-p 30.6 to 0.20 ms (155x). 11 new test functions, 23 cases, checked against a full-sort reference. Merged as PR #524 after two approvals.
Biggest caveat
These are sampler microbenchmarks on synthetic logits from the first revision of the PR, not end-to-end speedups, and the benchmark harness was not part of the merged change. One machine.
+387 −11
Lines changed
2 files: the sampler and its tests
129 + 258
Lines added to source and tests
twice as much test as implementation
3
Floating-point failure modes
Float drift, +inf trap, multi-+inf softmax
2
Approvals
after one changes-requested review and a second probe
11 days
Issue to merge
Nov 7 to Nov 18, 2026
5 / 5
CI jobs passing
lint, swift-format, swift-test, two python-test
The problem

Sorting a quarter of a million logits to keep a few dozen.

Top-p and min-p only need the head of the distribution. The sampler sorted all of it, for every token.

CompositeSampler.selectActiveIndices is the step that decides which tokens stay in play before one is drawn. With topK unset, applying top-p or min-p meant sorting the whole vocabulary by logit, on every generated token.

For Gemma 4 the vocabulary is 262,144 tokens. A comparison sort over that is on the order of V·log₂V ≈ 4.7 million comparisons, repeated per token, to find a nucleus that can be a small fraction of V. Worse, the work was wasted twice: it also fed a V-sized softmax and a V-sized multinomial scan.

Reported
Nov 7, 2026, by a contributor who later reviewed the PR
Their measurement
Gemma 4 E2B on an M4 Max: about 17 ms per token in sampling, about as long as the forward pass
Their consequence
Top-p decoding ran at about half the speed of greedy
Their proposal
Sort only tokens within 20 logits of the max (or above max + log(minP)): about 0.5 ms per token

Source: issue #499. Those timings are the reporter’s, from their machine.

Autoregressive decoding: one sampler call per generated token
forward passsample()unchangedthis PRtoken 1forward passsample()unchangedthis PRtoken 2forward passsample()unchangedthis PRtoken 3Schematic, not to scale. The sampler runs again for every token, so its cost is paid once per token generated.

In the issue, the reporter measured sampling at about 17 ms per token on Gemma 4 E2B (M4 Max), about as long as the forward pass, so top-p decoding ran at roughly half the speed of greedy. That figure is theirs, not mine, and it is the reason the problem was worth fixing: the sorted tokens are almost all irrelevant to the answer.

Per-token work, V = 262,144
VersionComplexityWhat happensWork
Before: sort everythingO(V log V)Every token, for any topP or minP without topK, ran (0..<vocabSize).sorted over all V logits.≈ 4.7 million comparisons
After: min-pO(V + m log m)One pass for the max, one to collect tokens at or above max + ln(minP), then sort only those m.two passes over V, small sort
After: top-pO(V + m log m)Passes for the max, bucket mass and collection, then sort only the prefix of m tokens that can reach topP.three passes over V, small sort

262,144 = 218, so V·log₂V = 262,144 × 18 ≈ 4.7 million comparisons. That is plain arithmetic about the sort, not a measurement. m is the number of tokens in the sorted prefix. The explorer below shows its size for a synthetic distribution.

The algorithm

Bound the tail, bucket the mass, sort only the prefix.

The key move is to locate where the nucleus ends without sorting, then sort only up to there.

  1. 01

    Find the max

    One vDSP_maxv pass over V logits. Everything else is measured relative to it, which also keeps exp() from overflowing.

  2. 02

    Set a logit cutoff

    top-p keeps tokens within ln V + 18 of the max. min-p keeps tokens at or above max + ln(minP). When both are set, the tighter bound wins.

  3. 03

    Bucket the candidates

    Each candidate goes into one of 2,048 buckets by its distance below the max, and its softmax mass exp(ℓ − max) is added to that bucket in Double.

  4. 04

    Walk down the buckets

    Accumulate bucket mass from the top until it reaches topP × total. Stop one bucket later, as slack for rounding at the bucket edge.

  5. 05

    Sort only that prefix

    Collect the tokens in those buckets in index order and sort them. The sort is stable, so ties resolve as they did when the whole vocabulary was sorted.

  6. 06

    Exact scan, unchanged

    The existing cumulative scan runs over the sorted prefix against the full candidate denominator and picks the precise cutoff in Double.

Filtering in logit space

min-p

min-p keeps a token when its probability is at least minP times the best token’s. Softmax makes the common denominator cancel, so the test needs no exponentials: it is a threshold on the raw logit.

pi ≥ minP · pmax ⇔ ℓi ≥ ℓmax + ln(minP)
p_i ≥ minP · p_max is equivalent to a threshold on the logit, so one pass over V finds the survivors.

Why a window, and why ln V + 18

top-p

For top-p there is no closed-form threshold, because where the nucleus ends depends on the shape of the distribution. What can be bounded is the part that cannot matter: tokens so far below the max that even all of them together are under the Float32 resolution of the cumulative sum.

V · e−(ln V + 18) = e−18 ≈ 1.5 × 10−8 < 2−24
Each ignored token has at most this fraction of the best token’s mass, and there are at most V of them.

That bound holds for any vocabulary and any distribution, which a fixed distance of 20 does not. Review caught this, and it is the first case under Correctness below.

A window alone is not enough

top-p

On a flat-ish distribution about half the vocabulary sits inside the window. The PR measured a window-only version at 12 ms for top-p: still sorting about half the vocabulary. So the candidates are put into 2,048 buckets by distance below the max, softmax mass is summed per bucket, and the walk down from the top bucket stops when it reaches topP.

b(ℓ) = min( B − 1, ⌊ (ℓmax − ℓ) · B / span ⌋ )
Bucket 0 is nearest the maximum. B = 2,048. span is the width of the candidate window in logits.

Only tokens in the buckets walked, plus one bucket of slack for rounding at the edge, are collected and sorted. The original exact cumulative scan then runs over that sorted prefix and picks the precise cutoff, so the result is the same nucleus a full sort would give, and the cost no longer depends on the distribution’s shape.

See it work

runs in your browser

This is a TypeScript port of the merged code, run on a 4,096-token synthetic distribution so it can recompute as you drag. The check beside the chart compares every setting to a full-sort reference.

Live: the algorithm on 4,096 synthetic logitsidentical to the full-sort result (13 tokens)
Bulk of the distribution
min-p filter
0.000.250.500.751.00topP 0.90at the max-15.3 (cutoff, 26.3 below the max)
cumulative softmax mass, bucket by bucket tokens that get sorted candidates never sorted
Vocabularyevery token
4,096
Candidatesabove the ln V + 18 window
4,096
Sorted prefixbuckets walked, plus one
13
Nucleusafter the exact scan
13

Bars use a log scale. Only 13 of 4,096 tokens (0.3%) are sorted. The logits are synthetic: a peaked head of 40 tokens plus a gaussian bulk, like the benchmark inputs. At the full 262,144 the same code path applies; the check script runs both sizes against a full-sort reference.

The implementation

verbatim, merge commit
CompositeSampler.swift · candidateIndicesAboveCutoff (excerpt, merge commit)
1var cutoff = -Float.infinity
2if topP != nil { cutoff = maxLogit - (logf(Float(logits.count)) + topPTailMargin) }
3if let m = minP { cutoff = max(cutoff, maxLogit + logf(m)) }
4 
5let bucketCount = nucleusBucketCount
6// Bucket 0 holds the logits closest to the max. A zero span (minP == 1) maps to bucket 0.
7let span = maxLogit - cutoff
8let scale: Float = span > 0 ? Float(bucketCount) / span : 0
9@inline(__always) func bucket(_ v: Float) -> Int {
10 min(bucketCount - 1, Int((maxLogit - v) * scale))
11}
12 
13var mass = [Double](repeating: 0, count: bucketCount)
14var total: Double = 0
15for v in logits where v >= cutoff {
16 let e = Double(expf(v - maxLogit))
17 mass[bucket(v)] += e
18 total += e
19}
20 
21// First bucket where the cumulative mass reaches topP, plus one bucket of slack.
22let target = Double(p) * total
23var cum: Double = 0
24var lastBucket = bucketCount - 1
25for b in 0..<bucketCount {
26 cum += mass[b]
27 if cum >= target {
28 lastBucket = min(b + 1, bucketCount - 1)
29 break
30 }
31}
32 
33var candidates: [Int] = []
34for (i, v) in logits.enumerated() where v >= cutoff && bucket(v) <= lastBucket {
35 candidates.append(i)
36}
37return (candidates.sorted { logits[$0] > logits[$1] }, total)

Lines 1 to 3 set the logit cutoff: the top-p window, tightened by min-p when both are set.

The span guard. When minP = 1.0 the window has zero width. Scale falls back to 0 instead of dividing by zero, and every token lands in bucket 0.

Double for mass. The per-token exp stays Float; the bucket sums and the running total are Double, so 262,144 additions do not lose small terms.

Stable order. Candidates are collected by ascending index and sorted by logit, so ties resolve as in a full sort. The total is returned so the caller’s exact scan uses the full denominator, not the trimmed prefix’s.

Correctness

The fast path was the easy part. The edge cases were the work.

Eight numerical and boundary cases, how each surfaced, and what the merged code does about it. Open any of them.

“Thanks for the fix. However this would trap when there is a +inf logit in topP, which would happen in an fp16 overflow.”

Reviewer, changes requested

“This is overstated, and model specific. A large vocab like Gemma 4’s can drop below.”

Reviewer, on the 20-logit window comment
01Window sizingHow far below the max can you safely ignore a token?

How it surfaced

My first version used a fixed 20 logits. The reviewer called the comment “overstated, and model specific”: a large vocabulary like Gemma 4’s can drop below it.

Why it matters

Each ignored token carries at most exp(−20) of the best token’s mass, but there are V of them, so the ignored tail grows with the vocabulary. In the worst case 262,144 × exp(−20) ≈ 5 × 10⁻⁴ of the mass is ignored, far above the resolution the cumulative scan works at.

What the merged code does

The window is now ln V + 18. Each ignored token has at most exp(−(ln V + 18)) of the best token, so all of them together carry at most exp(−18) ≈ 1.5 × 10⁻⁸, below the Float32 resolution of the cumulative sum (2⁻²⁴ ≈ 6 × 10⁻⁸). The bound holds for any vocabulary size and any distribution.

Evidence: Reviewer comment on the window

02Float vs DoubleFloat accumulation over 262,144 terms

How it surfaced

Running the large-vocabulary tests at 262,144 tokens, as the reviewer asked, exposed drift in the cumulative scan.

Why it matters

Summing a large nucleus in Float drops small terms. At 262k the Float scan drifted by about 1e-3, enough to move the cutoff by tens of tokens and change which tokens are sampled. The source comment makes the same point: over a large nucleus the drift moves the cutoff by tens of tokens.

What the merged code does

The bucket masses, the candidate denominator and the cumulative scan are all accumulated in Double. Per-token exp() stays Float. Results can differ from the old Float scan in rare draws, in the more accurate direction, which is why the reference in the tests is also Double.

Evidence: Commit 65be68e message

03Positive infinity+inf logit trapped the process

How it surfaced

Reviewer, changes requested: “this would trap when there is a +inf logit in topP, which would happen in an fp16 overflow.”

Why it matters

With a +inf max, the cutoff and bucket arithmetic go through inf − inf = NaN, and converting that to an Int traps at runtime. A Float16 model whose logits overflow would crash the sampler instead of producing a token.

What the merged code does

A +inf max returns before any bucket arithmetic, with only the +inf tokens as candidates. The guard exists in both the candidate selection and the caller, so no path reaches the NaN.

Evidence: Review requesting changes

04Softmax stabilitySeveral +inf logits: only the last was ever sampled

How it surfaced

After approval, the reviewer suspected more than one +inf token would still misbehave and posted a test. It failed.

Why it matters

softmaxVectorized subtracts the max before exp(). With a +inf max that is inf − inf = NaN, so only the last +inf token was ever returned and the others were unreachable. The bug sat in code older than my change, and it also affected the no-filter fast path.

What the merged code does

When the max is +inf the softmax is defined as its limit: uniform over the +inf positions, zero elsewhere. This fixed top-p, min-p, top-k and the unfiltered path. The reviewer’s test went in unchanged, plus a uniformity test (5σ bounds) and a direct softmax unit test.

Evidence: Reviewer’s test, my fix

05Float16 and maskingFloat16 overflow together with masked logits

How it surfaced

Guided generation masks forbidden tokens with −inf, and a Float16 model can overflow to +inf. The two have to coexist.

Why it matters

A vector containing both −inf and +inf is a realistic worst case: exp(−inf) = 0 is safe, +inf is not, and the active set must contain only the +inf tokens.

What the merged code does

A dedicated test builds 1,024 Float16 logits that are −inf except two +inf and one finite value, then samples with no filter, top-p, min-p and top-k plus top-p. It asserts that exactly the two +inf tokens are ever returned.

Evidence: Test: Float16 overflow to +inf, with −inf masked positions

06Masked logitsMasked and all-masked input

How it surfaced

Guided decoding pre-masks logits with −inf, so the new path must never admit them, even in an all-masked row.

Why it matters

A row that is entirely −inf has no maximum to measure distances from, so the selection must recognise it and stop.

What the merged code does

A −inf max returns an empty candidate set, and the caller falls back to index 0, exactly as before. With some finite logits, −inf tokens never pass the cutoff. A test asserts both.

Evidence: Test: topP never samples −inf positions, and all-−inf input falls back to index 0

07TiesTies and deterministic behaviour

How it surfaced

Existing seeded-reproducibility and greedy tie-breaking tests must keep passing, so selection order cannot change.

Why it matters

If candidates were collected out of order or sorted unstably, equal logits could swap places and the same seed would yield a different token.

What the merged code does

Candidates are collected in ascending index order and sorted stably, so ties resolve as in a full-vocabulary sort. A test with all 262,144 logits equal checks the nucleus is exactly ⌈0.9 V⌉ tokens in index order and matches the reference draw for draw.

Evidence: Test: topP matches the reference when the whole vocabulary is within the window

08Flat distributionsFlat distributions defeat a window on its own

How it surfaced

In the first benchmark, a window-only version of the change still took 12 ms for top-p. On a flat-ish distribution about half the vocabulary is inside the window.

Why it matters

A distance cutoff bounds the tail but says nothing about how many tokens sit above it. The cost then depends on the distribution’s shape.

What the merged code does

The bucketed mass walk locates where the nucleus ends without sorting anything, so the sorted prefix is small whatever the shape. This is the step that took flat-bulk top-p from 12 ms to 2.48 ms.

Evidence: PR description, motivation section

09Boundary conditionsBoundaries: zero-width windows and p close to 1

How it surfaced

topP combined with minP = 1.0 makes the window zero wide. topP = 1 − 10⁻⁶ must still reach the whole vocabulary.

Why it matters

A zero span would divide by zero in the bucket scale; a topP of almost 1 stresses the stopping condition on a flat vocabulary.

What the merged code does

A zero span maps every token to bucket 0 (scale 0), and the test asserts only the top token is returned across 200 draws. A 64-token flat distribution with topP = 1 − 10⁻⁶ is sampled 5,000 times and every token is seen.

Evidence: Tests: topP + minP = 1.0 keeps only the top token; flat distribution keeps all candidates

When the maximum is infinite

the softmax fix

Subtracting the max before exp() is what makes softmax stable, and it is also what breaks when the max is +inf: the subtraction is inf − inf. The merged fix defines the answer as the limit, a uniform distribution over the +inf positions, and applies it in softmaxVectorized itself, so every sampling path inherits it, including the unfiltered fast path.

CompositeSampler.swift · softmaxVectorized (excerpt, merge commit)
1// A +inf logit (e.g. fp16 overflow) dominates every finite one, so the limit of the
2// softmax is uniform over the +inf positions. Subtracting the max would give inf - inf = NaN.
3if maxLogit == .infinity {
4 var infiniteCount: Float = 0
5 for i in logits.indices {
6 let isInfinite = logits[i] == .infinity
7 logits[i] = isInfinite ? 1 : 0
8 if isInfinite { infiniteCount += 1 }
9 }
10 var invCount = 1 / infiniteCount
11 vDSP_vsmul(logits, 1, &invCount, &logits, 1, n)
12 return
13}
Review

Two review rounds made it a different change.

The merged version differs from the one I first submitted in its window, its accumulation type and its infinity handling. All of that came out of review.

  1. Nov 7Issue

    Issue #499 opened

    The issue’s author, who later reviewed the PR, measures about 17 ms per token in CompositeSampler on Gemma 4 E2B (M4 Max) and proposes sorting only a logit window.

  2. Nov 13Commit

    Claimed, then first implementation

    I claim the issue and open PR #524. Version one: min-p collects above max + ln(minP); top-p uses a 20-logit window, 2,048 buckets, a Double denominator, and 32k-vocabulary tests.

  3. Nov 14Review

    Review: changes requested

    The reviewer flags the +inf trap under fp16 overflow, calls the 20-logit claim overstated, and asks for tests at 262k.

  4. Nov 14Commit

    Second revision

    A +inf guard, a window of ln V + 18, a Double cumulative scan, and large-vocabulary tests at 262,144 tokens. The 262k run is what exposed the Float drift.

  5. Nov 16Review

    Approved

    The reviewer approves the revised implementation.

  6. Nov 17Review

    A second probe finds a deeper bug

    The reviewer suspects several +inf logits still break sampling and posts a failing test. softmaxVectorized produced NaN, so only the last +inf token was reachable.

  7. Nov 17Commit

    Softmax fixed at the root

    Uniform distribution over +inf positions, the reviewer’s test included unchanged, and tests for uniformity, Float16 overflow with −inf masks, and the softmax itself.

  8. Nov 18Merged

    Approved again and merged

    Second approval at 02:43 UTC. Squash-merged at 06:40 UTC as eed1a35, with the reviewer credited as co-author.

Performance

Sampler-level results, not an end-to-end claim.

Time per token for the sampler call, before and after, from the PR description.

CompositeSampler.sample, ms per token, linear scaleMacBook Air M1 · vocab 262,144 · 300 iterations
topP = 0.9, flat bulk12x
before
30.9 ms
after
2.48 ms
topP = 0.9, Gaussian bulk14x
before
31 ms
after
2.19 ms
minP = 0.05155x
before
30.6 ms
after
0.2 ms
topP = 0.95 + minP = 0.0291x
before
30.6 ms
after
0.34 ms
topK = 50 (path unchanged)none
before
0.226 ms
after
0.226 ms
Sampler time per token before and after, in milliseconds
ConfigurationBefore (ms)After (ms)Speedup
topP = 0.9, flat bulk30.92.4812x
topP = 0.9, Gaussian bulk312.1914x
minP = 0.0530.60.2155x
topP = 0.95 + minP = 0.0230.60.3491x
topK = 50 (path unchanged)0.2260.226none
Measures
Milliseconds per token for the whole CompositeSampler.sample call, including temperature scaling
Inputs
Synthetic logits: a peaked head of 40 tokens plus either a flat bulk or a Gaussian bulk
Build and machine
Release build, MacBook Air M1
Method
Before and after run through the same harness
Read this before the numbers
  • This is a sampler microbenchmark, not model inference. Sampling is one step of each generated token, next to a forward pass that this change does not touch. No end-to-end tokens-per-second figure is claimed here.
  • The numbers come from the PR description, written for the first revision. The later revisions (ln V + 18 window, Double scan, +inf guards) were not re-benchmarked in the PR, and the benchmark harness is not part of the merged change.
  • Inputs are synthetic logits, not outputs of a real model. Real model distributions may differ, and that was not measured.
  • One machine, an M1 Air. The issue’s own 17 ms figure is from an M4 Max with a real model, so absolute times differ; before and after were measured with the same harness.
  • The topK path is unchanged and shows no speedup, as expected.

Source: the benchmark table in the PR description, reproduced as written. I did not re-run it for this page, because the harness was not committed.

Validation

Twice as much test code as implementation.

258 lines of tests against 129 of source: 11 new test functions, 23 parameterised cases, each judged against a full-sort reference or an exact expectation.

Equivalence with a full-sort reference

3 functions, 6 cases

  • topP / minP without topK vs the reference at 262,144 tokens: four configurations (top-p 0.9, top-p 0.5 at temperature 0.7, min-p 0.05, top-p 0.95 + min-p 0.02), 40 seeded draws each
  • Flat-bulk distribution where nearly half the vocabulary is inside the window, 40 draws
  • All 262,144 logits equal, so every token is a candidate, 40 draws

Distribution edge cases

3 functions

  • Flat 64-token distribution with topP = 1 − 10⁻⁶ still reaches every token in 5,000 draws
  • −inf masked positions never sampled, and all-masked input falls back to index 0
  • topP with minP = 1.0 (zero-width window) returns only the top token, 200 draws

Infinities and Float16 overflow

5 functions, 14 cases

  • A +inf logit is sampled without trapping, across four configurations, at 262,144 tokens
  • Every +inf logit is reachable: top-p, min-p, top-k + top-p (the reviewer’s test, included unchanged)
  • +inf logits are sampled uniformly on five paths, with 5σ binomial bounds over 4,000 draws
  • Float16 overflow to +inf with −inf masks samples only the +inf tokens
  • softmaxVectorized of a vector with +inf entries is exactly [0, 0.5, 0, 0.5, 0]

What was verified, and by whom

Reference
A full-sort reference in the tests mirrors the old behaviour, computed in Double
PR description
New code matched an exact Double full-sort reference on 300 of 300 seeded draws at 262k (first revision)
Final tests
40 seeded draws per configuration at 262,144, asserted draw for draw against the reference
Test suites
PR description: 65 tests across CompositeSampler, MPSGraphSampler, LogitRowScan and WhitespaceLimitSampling passed (first revision)
Final CI
lint, swift-format, swift-test and both python-test jobs passed on the merged run
Formatting
swift format lint --strict clean, which I reported running locally on the final commit
Not run
The PR description states the full LanguageModelsTests target was not run at first submission; the final comment reports a full swift test --no-parallel pass

Honest limits

  • Hardware: the benchmarks are from one MacBook Air M1. I did not measure on an M4 Max or on a real model’s logits.
  • The change does not make the model faster by these multipliers. It removes one per-token cost; the forward pass is unchanged.
  • top-p results can differ from the old implementation in rare draws, because the old Float sum was less accurate. The PR description says so; it is a correctness improvement, not a regression.
  • When topK is set, the old behaviour is kept, and the code comment notes that top-p inside a top-K window is numerically equivalent to a global top-p for realistic distributions.
  • The window argument bounds the ignored mass by exp(−18). It is a bound at Float32 resolution, not an exact-arithmetic guarantee, which is why the exact scan still runs over the sorted prefix.
Code and links

Everything is public. Check it yourself.

  • Merged pull request#524 · Merged Nov 18, 2026
  • Original issue#499 · closed by the merge
  • Merge commiteed1a35
  • Source fileCompositeSampler.swift at the merge commit
  • Test fileCompositeSamplerTests.swift at the merge commit
See it for yourself

Reviewed twice, tested at 262,144 tokens, merged.

Read the merged PRView the source