What is taught wrongly

A parameter that waits for another

Four merge fold shapes over thirty-two evenly loaded shards leave errors of 665, 667, 665 and 667 — a fifth of a per cent apart. Give the same four shapes shards whose loads span seventeen-fold and they leave 148, 183, 323 and 403. The parameter did nothing until a second parameter moved, and every measurement that fixed the second one saw nothing.

Here are four fold shapes measured on thirty-two Misra-Gries summaries under round-robin partitioning, where every shard gets exactly 1,250 arrivals.

Chain: 918. Balanced tree: 917. Size-ordered: 917. Largest-first: 919.

That is a spread of two counts in nine hundred — a fifth of a per cent — across four constructions that build trees of height 31, 5, 5 and 31 and that any reasonable person would expect to differ. An essay that measured this and moved on would have been right to.

The fold shape is worth nothing until the partition is unevenThe worst error over the sixteen heaviest keys after folding 32 shard summaries of 32 counters, for four fold shapes under three partitions. Round-robin and blocked give every shard the same load, and the four shapes then agree to 0.2% — a size-ordered fold on equal weights *is* a balanced tree. Hashing leaves the loads spanning 18-fold, and the same four shapes span 2.7 times. Nothing about the structures changed between the groups.01002003004005006007008009001000roundloads 1.0×blockedloads 1.0×hashedloads 17.6×worst error over the heaviest keyschaintreesmallest-firstlargest-first32 shards · k = 32 · 40,000 arrivalseven 1.00× · uneven 2.7×
Fig. 1 Four shapes under three partitions. The first two groups give every shard the same load and the four bars are the same height. The third gives loads spanning seventeen-fold and the bars span 2.7 times.

Here are the same four shapes on the same stream sharded by hashing instead, where the loads run from 402 to 7,087.

Chain: 323. Balanced tree: 148. Size-ordered: 183. Largest-first: 403.

Why the even case is exactly flat

Two of the four collapses are identities rather than coincidences, and it is worth separating them from the third.

Size-ordered is the balanced tree. Huffman’s construction on equal weights builds a complete tree — the two smallest are any two, their union is heavier than the remaining singletons, and the pool works through a full level before starting the next. So the two shapes are the same tree, and their weighted path lengths agree exactly: 200,000 and 200,000. Not close; equal.

Largest-first is the chain. Its first merge takes the two largest, whose union is now larger than any singleton, so it takes the union and the next singleton, and so on. Height 31, same as the plain chain. The two differ only in which shard enters when, and under equal loads there is no “which”.

So under an even partition there are not four shapes. There are two, and the remaining question is why those two agree to a fifth of a per cent when a chain applies thirty-one cuts and a tree applies five.

Misra-Gries: keys whose count depends on the order the shards were combinedThree merge orders over the same 40,000 arrivals: folded in one at a time, combined pairwise in a tree, and folded in with the shards reversed. All three are the same associative-looking operation applied to the same summaries, and the tables they produce are not the same table. At 32 shards, 32 keys carry a different count depending only on the shape, the largest difference being 5 arrivals. Nothing in a deployment fixes the shape: a coordinator folds, a parallel reduction trees, and a retry changes the order.0217427841163232shards mergedkeys whose count movedthree orders:folded in one at a timecombined pairwise, in a treefolded in, last shard firstMisra-Gries, k = 32 · roundworst gap 5 arrivals
Fig. 2 Chain against tree under round-robin, across shard counts. The two lines sit on each other. The same plate under hashing is the one that separates.

The answer is that under round-robin every shard is a uniform sample of the same stream, so every shard holds the same keys. A Misra-Gries merge cuts by the (k+1)(k+1)-th largest count in the union of the two tables — and if the two tables hold the same thirty-two keys, their union holds thirty-two keys, there is no thirty-third, and the cut is zero.

A fold of identical tables takes no cuts at all, at any depth, in any order. Thirty-one zeroes and five zeroes are the same sum. The shape parameter is multiplied by a quantity that the partition has set to nothing.

What the uneven case supplies

Hashing sends each key to exactly one shard. So two shards hold disjoint key sets, their union holds up to sixty-four keys against a table of thirty-two, and there is a thirty-third largest to cut by.

Now the fold has cuts in it, the cuts are sized by the mass at each node, and the shape decides how many of each size a survivor passes through. The measured cut totals are 309, 254, 259 and 388, and the damages track them.

This is the same structural fact the partition the analysis did not mention priced from the other direction. There, the partition was shown to change which structure pays; here it is shown to change whether a third parameter is connected to anything at all.

The number that says which regime a deployment is in

If the shape’s leverage depends on whether the shards hold different things, then the quantity to look at is how different they are — and there is one already computed.

The load spread is the crude version: 1.00 under round-robin and blocked, 17.6 under hashing. It is crude because it is about mass and the mechanism is about keys; two shards could hold equal masses of entirely disjoint keys and the spread would report nothing while the cuts were large.

The sharper version is the distinct load — how many keys the mm tables hold between them, against the mkm \cdot k slots the deployment allocated. Under round-robin at thirty-two shards that is a little over thirty keys against 1,024 slots, because every table holds the same ones. Under hashing it approaches 1,024, because they hold disjoint ones. That ratio is what decides whether a merge has anything to discard, and it is computed from the shard histograms before any structure is allocated.

The bill a partition only divides is where that quantity was introduced, for a different purpose. It turns out to be the gate on this parameter too, which is the kind of reuse that suggests it is the right quantity rather than a convenient one.

One bill per key, split by which structure is holding itEach row is one of the 8 heaviest keys. The left segment is what a Space-Saving merge will pay for it — a floor for every shard where the key sits under that shard's floor — and the right segment is what a Misra-Gries merge will pay — that shard's floor for every shard where it sits over. The key's own frequency cancels out of the sum, so every row is the same length: 967 arrivals, the sum of the 8 shard floors. The partition does not change the size of the bill. It decides where the line falls.f = 6,3628/8 holdingf = 3,0748/8 holdingf = 1,9638/8 holdingf = 1,3738/8 holdingf = 1,0988/8 holdingf = 9353/8 holdingf = 7690/8 holdingf = 6560/8 holdingpredicted damage, in arrivals — every row totals 967Space-Saving's shareMisra-Gries's share8 shards · round · k = 32bill 967 arrivals
Fig. 3 Where a heavy key’s arrivals sit under round-robin: everywhere, in roughly equal parts. A key present on every shard is never absent from either side of a merge, which is why one structure’s fold charges it nothing at all.

The shape of the measurement failure

The generalisation is worth stating carefully, because “vary two parameters instead of one” is both correct and useless as advice — the number of pairs is quadratic and most of them are independent.

The useful version is narrower. When one parameter multiplies a quantity that another parameter can set to zero, measuring the first at the second’s zero measures nothing, and the result is not “small effect” but “no information”. Those are different findings and a table of numbers reports them identically.

What distinguishes them is available before the measurement and costs nothing: look at the mechanism and ask what the parameter acts on. The fold shape acts on the sequence of cuts. If there are no cuts, it acts on an empty list. That question is answerable by reading the merge rule, and it would have flagged round-robin as the wrong partition to measure the shape under without a single run.

It is the same trap as a benchmark run on an input the code has a special case for, and it fails the same way: quietly, in the direction of “no difference found”, which is the direction a tired reader accepts. A limit is not a prediction is this site’s standing warning about believing an asymptotic statement at a size nobody ran; this is the version where the statement is fine and the input has switched the phenomenon off.

The reason it is worth a whole essay rather than a caveat is that the flat result is genuinely informative once it is understood. “The four shapes agree to a fifth of a per cent under round-robin” is not a null result — it is a prediction of the mechanism, and a strong one, because the mechanism says the agreement should be exact for two of the pairs and near-exact for the third. Getting 917, 917, 918 and 919 is the mechanism passing a test, not the measurement failing to find anything.

It needs depth as well

The partition is necessary and it is not sufficient, which the shard sweep makes plain.

At two shards there is one merge and every shape is the same shape. At four there are three merges and a chain of four differs from a tree of four by two levels. At thirty-two the chain applies thirty-one cuts and the tree five, and that is where the 2.7 appears.

So the shape’s effect is a product of two conditions — an uneven partition and a deep fold — and a deployment satisfying only one of them can fold however it likes. That is most small deployments, and it is another reason this has stayed unmeasured.

Space-Saving, which has no cuts at all

The other counter structure gives the same answer through a different mechanism, and the agreement is worth having.

Space-Saving’s merge takes no cut. For a key absent from one side it adds that side’s floor, and nothing is subtracted from anybody. So the quantity the shape acts on is not a list of cuts but a list of floors — the floor of whatever summary the key was merged against, at each level.

Under round-robin the heavy key is present in every shard, so it is never absent from either side of any merge, and it is charged nothing at all whatever the shape. Under hashing it lives in one shard and is absent from every other, and now the floors on its path are what it pays. The measured damages are 634, 457, 469 and 501 against a flat 665-to-667 under round-robin.

Two structures, two unrelated merge rules, and the same conditional: the shape matters when and only when the partition makes the shards hold different things.

That the two agree is worth more than either result. The structures are the same structure under a stream — two structures that are one is where this site established that — and they stop being the same structure under a merge, which is the whole of the reversal those essays measured. So an agreement between them about a third parameter, arrived at through two different mechanisms, is evidence that the conditional is about the partition rather than about either merge rule.

Where this leaves the two folds built for it

The size-ordered fold was built for these essays, to test whether the construction that provably minimises a weighted path length also minimises a merge’s bill. The fold that minimises the wrong thing is the answer — it does not — and the identity above is what makes that a finding rather than a coding error.

Under round-robin the size-ordered fold’s path length is exactly the balanced tree’s, to the arrival, because equal weights make the two constructions the same tree. That equality is the strongest available check that the builder is doing what it claims: an approximate agreement could be luck, and an exact one across every even partition cannot be. Under hashing it is 123,134 against the tree’s 147,365, which is a genuine 16% improvement in the thing Huffman minimises.

So the two partitions do two different jobs for that essay. The even one certifies the construction; the uneven one is where the construction has something to be optimal about, and where it loses on the quantity that is actually being paid.

The shape one structure will not fold then depends on the same condition from the other side. The trade it describes — a shape that saves a quantile summary a fifth of its space and costs a counter table 2.7 times its error — exists only under hashing. A deployment on round-robin holds two structures that both do not care, and has no decision to make.

What else has been measured at a zero

The uncomfortable question this raises is what else on this site was measured with a second parameter parked where it switches the first one off, and it deserves an honest answer rather than a reassuring one.

The audit is not hard for this strand, because there are only a few parameters. The bias function was swept under a fixed partition, and the bias acts on the cap rather than on the merge, so the partition does not gate it. The window length was swept under a fixed arrival process, and the boundary that hides the burst is precisely the finding that the arrival process gates it — that one was caught, and it was caught by building the process that made it non-zero.

The one that is genuinely open is the tolerance. Everything about ε\varepsilon in this collection is measured under a stationary stream, and a stationary stream is the one where the summary’s realised error is furthest below its promise. Whether ε\varepsilon’s effects look different where the promise binds is not something measured here.

A third parameter that behaves the same way

The pattern is not unique to the fold shape, and one more instance is worth putting beside it because it was found the same way and in the same strand.

The merge’s bias function — whether a quantile summary’s cap is uniform, tail-weighted or head-weighted — is worth a large factor in state, and it is worth nothing at all in the counter tables, which have no cap. That is trivially true and nobody would measure it. The non-trivial version is that the bias’s effect on a merge depends on the shard count: the cheap tail and the expensive merge measures the biased family at 6.3 times the unbiased one at two shards and 3.7 at sixty-four, which is a factor of 1.7 in the ratio itself across the sweep. Measured at one shard count it is one number; measured at two it is a trend.

And the counter width kk is a fourth. It gates the fold shape as surely as the partition does, from the other side: at kk large enough to hold the union of every table, no merge ever discards, and the shape is again multiplied by zero. That is the same identity as the round-robin case reached by making the table bigger rather than the shards more alike, and it means a deployment can switch this whole phenomenon off by over-provisioning kk — which is worth knowing, and is not free, and is measured nowhere here.

Switching it off with kk costs more than the structure is for

The fourth gating parameter named above — a table wide enough that no merge ever discards — deserves a price, because it is the one a deployment might reach for without noticing what it has bought.

Under hashing at thirty-two shards the tables hold nearly disjoint key sets, so their union approaches mkm \cdot k: about a thousand keys against a table of thirty-two. To make the final merge discard nothing, kk has to hold that union, which means raising kk by a factor of thirty-two — and kk is per shard, so the deployment’s total state goes from 32×32=1,02432 \times 32 = 1{,}024 counters to 32×1,024=32,76832 \times 1{,}024 = 32{,}768.

Now compare that against the thing a summary is an approximation of. The universe here is 2,048 keys, so an exact count of every key in the stream is 2,048 counters. The over-provisioned sharded deployment is sixteen times larger than counting everything exactly, and it is still approximate.

The crossing arrives long before the switch-off does. A sharded deployment costs mkm \cdot k counters and an exact one costs UU, so the summaries stop being a saving at

k  =  Um  =  64k \;=\; \frac{U}{m} \;=\; 64

— one doubling of the current width. Past sixty-four counters a shard, thirty-two summaries of this stream cost more than counting every key exactly, and the merge damage they are still paying is a cost the exact count does not have.

So the kk route is not a way of switching the phenomenon off; it is a way of leaving the regime where approximate counting is the right tool, and arriving there by a parameter that looks like a quality dial. The honest form of the option is: if kk can be raised to U/mU/m, do not shard summaries at all.

Against which the fold shape is free. Choosing a balanced tree rather than largest-first takes the measured damage from 403 to 148 — a factor of 2.7 — at no cost in memory, no change to any structure, and one line in whichever code arranges the reduction. Two levers on the same quantity, one of them costing thirty-two times the memory and the other costing nothing, and only the expensive one is a parameter anybody thinks of as tunable.

That is worth stating as the practical reading of this whole essay. The fold shape is invisible under an even partition and worth a factor of 2.7 under an uneven one; the width is visible everywhere and is the wrong lever for this particular damage; and which of the two a deployment reaches for is decided by which one has a name in the configuration file.

The items that survive kk counters is where the width’s real job is measured — deciding which keys a single table holds, which is a question about a stream rather than about a merge. The fold that minimises the wrong thing is where the free lever turns out not to be free of subtleties either: the construction that provably minimises the path length is not the one that minimises the bill.

The same four shapes over the other counter structure say that the conditional is about the merge rule and not only about the loads.

The fold that minimises the path length is not the fold that minimises the billSpace-Saving over 32 shards whose loads span 17.6-fold, folded four ways. The weighted external path length is the quantity Huffman's construction minimises by proof, and the size-ordered fold does minimise it — 181,407 against the balanced tree's 200,000. The damage does not follow it: the tree leaves 457 and the size-ordered fold 469. Space-Saving's merge takes no cut at all — it charges the absent side's floor — so the middle column is empty here and the ordering has to come from the floors themselves.weighted path lengthΣ wᵢdᵢ — what Huffman minimisescuts takenΣ over the mergesdamageworst error leftchaintreesmallest-firstlargest-first719k200k181k920kno cut is taken634457469501Space-Saving · 32 shards · hashedleast path smallest · least damage balanced
Fig. 4 Space-Saving over the same thirty-two shards, whose loads span 17.6-fold, folded four ways. The size-ordered fold does minimise the weighted external path length — 181,407 against the balanced tree’s 200,000 — and the damage does not follow it: the tree leaves 457 and the size-ordered fold 469. The middle column is empty, because this structure’s merge takes no cut at all and charges the absent side’s floor instead.

And the two structures want opposite shapes, which is the thing a deployment folding both of them cannot arrange.

The shape one structure wants is the shape the other refusesFour fold shapes over 32 shards under hashed partitioning. The counter tables are cheapest under a tree and dearest under a largest-first, by a factor of 2.72. The quantile summaries are the other way round: the largest-first keeps 2,556 tuples and the tree keeps 3,211. Each column is a ratio against its own best shape, because a damage in counts and a tuple count are not the same quantity. A deployment folding both cannot be right twice.counter tablesworst error, ratio to bestquantile summariestuples kept, ratio to bestchain2.18× (323)1.10× (2,807)tree1.00× (148)1.26× (3,211)smallest-first1.24× (183)1.28× (3,278)largest-first2.72× (403)1.00× (2,556)32 shards · hashed · k = 32each column against its own best shape
Fig. 5 Four fold shapes at thirty-two shards, each column a ratio against its own best shape because a damage in counts and a tuple count are not the same quantity. The counter tables are cheapest under a tree and dearest under a largest-first, by 2.72×; the quantile summaries are the other way round — largest-first keeps 2,556 tuples and the tree keeps 3,211.

Halving the shard count halves the depth and leaves the finding where it was, which is the check that the effect is about the loads rather than about how many levels there are to accumulate over.

The fold that minimises the path length is not the fold that minimises the billMisra-Gries over 16 shards whose loads span 8.6-fold, folded four ways. The weighted external path length is the quantity Huffman's construction minimises by proof, and the size-ordered fold does minimise it — 78,741 against the balanced tree's 101,260. The damage does not follow it: the tree leaves 157 and the size-ordered fold 165. The middle column is the quantity that does track — the sum of the cuts the fold took, whose least is balanced, the same shape as the least damage. A level is not a fixed charge; the cut at a merge grows with the mass under it.weighted path lengthΣ wᵢdᵢ — what Huffman minimisescuts takenΣ over the mergesdamageworst error leftchaintreesmallest-firstlargest-first214k101k79k324k187165170249218157165287Misra-Gries · 16 shards · hashedleast path smallest · least damage balanced
Fig. 6 Sixteen shards rather than thirty-two, loads spanning 8.6-fold rather than 17.6. The size-ordered fold still minimises the weighted external path length — 78,741 against the balanced tree’s 101,260 — and the damage still does not follow it: 157 for the tree against 165. The middle column, the sum of the cuts, still tracks the damage, because a cut grows with the mass under it and a level does not.

The check this leaves behind

The claim here is a conditional and it is checked as one, in both directions: on the even partitions the four shapes must agree to within a fifth of a per cent, and on the uneven one they must differ by at least a factor of two.

Either clause alone passes on something useless. A check that only required the flat result would pass on a fold implementation that had quietly stopped varying its shape — which is the exact failure a green gate is most likely to be hiding, since a broken shape parameter produces four identical numbers everywhere and looks like a clean negative result. A check that only required the large result would pass on a measurement with no control in it.

The fold that minimises the path length is not the fold that minimises the billMisra-Gries over 32 shards whose loads span 17.6-fold, folded four ways. The weighted external path length is the quantity Huffman's construction minimises by proof, and the size-ordered fold does minimise it — 123,134 against the balanced tree's 147,365. The damage does not follow it: the tree leaves 148 and the size-ordered fold 183. The middle column is the quantity that does track — the sum of the cuts the fold took, whose least is balanced, the same shape as the least damage. A level is not a fixed charge; the cut at a merge grows with the mass under it.weighted path lengthΣ wᵢdᵢ — what Huffman minimisescuts takenΣ over the mergesdamageworst error leftchaintreesmallest-firstlargest-first543k147k123k738k309254259388323148183403Misra-Gries · 32 shards · hashedleast path smallest · least damage balanced
Fig. 7 The uneven case in full: path length, cuts and damage for the four shapes. This is the plate the flat groups have to be contrasted against, and it is the one that says the shapes are genuinely different constructions.

The honest limit is that “even” here means two partitions that are even by construction — round-robin and blocked, both of which give exactly 1,250 arrivals per shard. Nothing between the two extremes is measured. Where the crossover sits, and whether the shape’s leverage rises smoothly with the load spread or turns on at some threshold of disjointness, is a sweep nobody has run and the machinery now supports.

Named alongside this one

Essays reaching for the same objects. Nobody chose these; they are what the concept index makes visible.

What links here

Every essay whose body links to this one.

The objects this essay names

Each one links to every other essay that touches it.

BenchmarkingCounterexampleHeavy hitterMeasurementMerge treeMergeable summaryMisra–GriesModelParameter choicePartitionShardSpace-savingTrade offTwo parameter boundWeighted path length