# Count once-observed objects without changing the denominator

A one-hit-wonder ratio answers a narrow question: of the distinct identities
seen in this window, how many were requested exactly once? It does not
measure cache hits, transferred bytes or future usefulness.

For counts f(x), let U be the number of observed distinct identities and S
the number with f(x)=1. The object ratio is S/U. The share of requests to
singleton objects is S/N, where N counts requests. Neither ratio is defined
for an empty window.

## Three different answers from AABC

These are constructed examples, not measurements of a deployed system.

| Observation | Requests N | Distinct objects U | Singletons S | S/U |
| --- | ---: | ---: | ---: | ---: |
| Complete AABC | 4 | 3 | 2 | 2/3 |
| First three requests AAB | 3 | 2 | 1 | 1/2 |
| Last three requests ABC | 3 | 3 | 3 | 1 |

For the full trace, singleton objects contribute half the requests, yet
two thirds of the distinct objects. Across the two three-request windows,
the pooled ratio is (1+3)/(2+3)=4/5. The unweighted mean is (1/2+1)/2=3/4.
Pooling weights each window by its distinct-object count. An object can
contribute in several overlapping windows; those pairs are not distinct
objects in the whole trace.

The checked [example JSON](example.json) includes all widths for this trace.

## A window is part of the measurement

The SOSP 2023 S3-FIFO study sizes sequences by their distinct objects.
Its shorter-window observation motivates rapid removal of unreused entries.
A fixed number of requests is a different sampling rule. NSDI 2024's SIEVE
analysis similarly explains pressure on newly inserted, unpopular objects.
Neither mechanism turns a trace singleton into an intrinsic property of
an object.

Extending AABC to AABCBC removes both singleton classifications. AAB,
AABB and AABBC have full-trace object ratios 1/2, 0 and 1/3, respectively:
the ratio can fall and then rise. This elementary example does not contradict
an expectation under a specified stochastic workload.

Frequency alone also loses ordering: AABB and ABAB both have two identities,
each seen twice. With a cold one-slot cache and immediate admission, the first
sequence misses twice and the second four times. No eviction-policy ranking
or hit-ratio estimator follows from the singleton fraction alone.

## Keep the source's sampling assumptions

S3-FIFO section 3.1 states its formal observation for an expected ratio under
a Zipf popularity model. The least-popular object has one request, and the
subsequence ends in a one-hit wonder. That conditional setup is different
from an arbitrary prefix or our enumeration of every complete request window.
The production-trace summaries do not turn it into a per-trace guarantee.

As a source-arithmetic check, the counter now reproduces Figure 1's three
prefixes: 17 requests contain 1 singleton among 5 objects; 7 contain 2 among
4; 4 contain 2 among 3. The last fraction is exactly 2/3, displayed as a rounded
67% in the paper. This checks a published toy example, not the production
measurements or the stochastic observation.

## Exact all-window counting

[model.mjs](model.mjs) reuses the existing
[footprint counter](../footprint-windows/model.mjs) for distinct-object/window
counts. For each occurrence at position i, let p be its preceding occurrence
(or -1) and q its next occurrence (or N). Windows in which this occurrence
is the only copy choose a left extent x from 1..a and a right extent y
from 1..b, where a=i-p and b=q-i. Their length is x+y-1.

For width w, this occurrence contributes

    max(0,w) - max(0,w-a) - max(0,w-b) + max(0,w-a-b)

singleton-object/window pairs. Four slope changes represent this triangular
or trapezoidal function. Summing slope changes and integrating once over
widths avoids recounting every window. Each request contributes at most four
updates; counting uses linear passes and O(N+U) storage with expected
constant-time map operations. Reduced output fractions additionally use
integer greatest-common-divisor calculations.

This is a direct interval-counting derivation, not a new cache theorem or
a reproduction of the papers' measurements. For at most one million requests,
the pair counts and intermediate counting values remain within JavaScript's
safe-integer range. The API rejects empty/sparse arrays and non-string or
empty identities; it performs no normalization of valid identity strings.

## Reproduce

From the site's root, with Node.js 24:

    node --test public/research/one-hit-windows/model.test.mjs
    node public/research/one-hit-windows/example.mjs --check

Import oneHitCurve(trace) from model.mjs. The result contains one row for
every width w=1..N, using all N-w+1 complete overlapping request windows.
Rows expose singletonObjectWindows, distinctObjectWindows, meanSingletonObjects
and pooledObjectRatio. Fractions are reduced numerator/denominator objects.
The result intentionally does not claim an unweighted mean of ratios.

The independent oracle directly recounts each window for all 3,279 traces
over a three-identity alphabet with lengths one through seven. Other tests
cover endpoint windows, renaming, reversal, immutable inputs and counts above
2^32. The existing footprint implementation and its tests remain unchanged.

Overlapping windows are dependent. These exact counts do not justify treating
them as independent statistical samples. Clock duration, object size,
admission, expiration, mutation and missing observations are outside this
identity-only calculation.

## Primary Sources

- Juncheng Yang, Yazhuo Zhang, Ziyue Qiu, Yao Yue and K. V. Rashmi.
  FIFO Queues are All You Need for Cache Eviction. SOSP 2023, sections 3.1-3.2.
  DOI: 10.1145/3600006.3613147.
  https://www.pdl.cmu.edu/PDL-FTP/Storage/FIFOqueues-SOSP23.pdf
- Yazhuo Zhang, Juncheng Yang, Yao Yue, Ymir Vigfusson and K. V. Rashmi.
  SIEVE is Simpler than LRU: an Efficient Turn-Key Eviction Algorithm for Web Caches.
  NSDI 2024, sections 2.1 and 5.1.
  https://www.usenix.org/system/files/nsdi24-zhang-yazhuo.pdf

Sources accessed 2026-11-27. Papers are linked, not redistributed.
The original counter and tests are CC0-1.0, like the reused footprint helper.
