Summary card: diff of 100,000 keys in 0.20 s, 100 list requests against 100,000 head requests

You migrated a photo library, a backup or a release archive into a bucket and the job log says it finished. A list of what should be there (a manifest: a CSV from the old system, a database export, the file list of the source folder) is the only way to prove nothing was lost on the way and nothing stray was left behind. The comparison is two lists of 100,000 keys. This article measures how to do it, what it costs in requests, and the one mistake that turns a clean bucket into 99,987 false alarms.

We built a 100,000-key manifest, a listing of the "bucket" as 100 real-format ListObjectsV2 pages, and planted three kinds of fault: 137 keys missing from the bucket, 83 stray keys the manifest does not know, and 25 keys whose size differs. Then we timed five ways of finding them.

What was measured, and what was not

  • Measured: the comparison step, on 100,000 and on 1,000,000 keys: seconds, peak memory, and whether the answer was exactly 137 / 83 / 25. The listing pages are XML files in the ListObjectsV2 response format (Key, LastModified, ETag, Size, StorageClass), 1,000 keys each, parsed with Python's ElementTree, so parsing cost is included.
  • Not measured: network time. The pages were read from local disk, so no latency figure for any storage service appears below; request counts follow from the API's 1,000-keys-per-page limit, and time per request is a stated assumption where we use one.
  • Keys look like photos/2026/07/3f/9a1c02d4-004217.jpg; the manifest was exported in shuffled order (a database export need not be sorted) and also saved sorted. Mac mini, Apple M4, Python 3.12.9, one fresh process per run, median of 7 runs for 100,000 keys and 3 runs for 1,000,000. Memory is the process's peak resident size; an empty interpreter is 14.5 MB.

Result 1: the diff costs almost nothing, reading the lists is the work

Method (100,000 manifest keys, 99,946 listed)Median time, sPeak memory
Reading 100 pages + the manifest, no comparison0.1925-28 MB
Hash set (dict of the listing, scan the manifest)0.2253-56 MB
Set difference (both sides as sets)0.2360-65 MB
Sorted merge, manifest already sorted0.2025-28 MB
Sort the manifest, then merge0.2451-52 MB

Every method found exactly 137 missing, 83 extra and 25 changed keys, in all 7 runs. Reading the pages and the CSV takes 0.19 s of the 0.20 to 0.24 s, so the choice between methods moves the total by 0.04 s at this size. Memory is where they differ: a hash set holds one side in RAM (about 28 MB more than the bare reader), the sorted merge holds two rows at a time.

Result 2: at 1,000,000 keys memory is the difference

Method (1,000,000 manifest keys, 999,460 listed)Time, s (3 runs)Peak memoryFound
Hash set2.56 to 2.58316 to 330 MB1,370 / 830 / 250
Sorted merge, manifest sorted2.00 to 2.0427 MB1,370 / 830 / 250
Sort the manifest, then merge2.66 to 2.74306 to 308 MB1,370 / 830 / 250

Ten times the keys: ten times the hash set memory (about 320 MB), still 27 MB for the merge, which streams. Sorting an unsorted manifest brings the memory back, because the whole list has to be held to sort it. Python object overhead dominates here; in Go or Rust the same sets are several times smaller, but the shape is the same: a hash set grows with the key count, a merge does not. For a 100 million key bucket, Python's hash set would want tens of gigabytes; the streaming merge would not, as long as both sides arrive sorted (an external sort of the manifest costs disk, not RAM).

Result 3: the mistake that makes 99,987 keys "missing"

A merge assumes both inputs are in the same order. We fed the manifest in export order (shuffled) straight into the merge. The answer was 99,987 missing and 99,933 extra, against 137 and 83 true, and not one changed key was seen, because the sizes were never compared. No error is raised; the report just looks like a disaster. Two rules prevent it:

  • Sort the manifest the way the bucket lists: by the UTF-8 bytes of the key. In a shell that is LC_ALL=C sort; in Python, key.encode() or plain string comparison; in Java or JavaScript, compare UTF-8 bytes, not UTF-16 units, or keys with characters outside the Basic Multilingual Plane sort differently. A spreadsheet or a locale-aware sort reorders punctuation and case and breaks the merge the same way.
  • Normalise names first. On tport.space, NFC and NFD spellings of a name are one object and the listing is ordered by the NFC form (Unicode object keys in S3), so a manifest made on a Mac needs NFC before it is compared, or every accented name shows up as missing and extra at once. A hash set does not care about order, which makes it the forgiving choice when you cannot trust the sorting.

Result 4: requests, which is where the time goes

Way to learn what the bucket holds (100,000 keys)RequestsTime if each call takes 0.3 sWith 16 in parallel
ListObjectsV2, 1,000 keys a page (99,946 listed = 100 pages)10030 snot possible per bucket: each page needs the previous token
HeadObject for every manifest key100,0008 h 20 min31 min
Same listing at 1,000,000 keys1,0005 min-

The 0.3 s is an assumption chosen for the sums, not a measurement: use your own latency (the arithmetic is requests times seconds per request). The point is the ratio: a listing needs one request for every 1,000 keys, a per-key check needs one for each. The diff itself, 0.2 s, is smaller than a single round trip of the listing. A HEAD per key also cannot find the stray keys, because it only asks about names you already know: the 83 extra keys would never appear.

To speed up a listing split it by prefix. With a prefix per month (12 here), 12 listings can run side by side, each about 8 pages, and the merge runs per prefix. The ordering rule above still holds inside each prefix.

The shortcut for keys only

When names are all you need, two sorted files and comm do the whole job, with no code to get wrong:

bash
LC_ALL=C sort manifest_keys.txt > m.sorted
LC_ALL=C sort listing_keys.txt  > l.sorted
LC_ALL=C comm -23 m.sorted l.sorted > missing.txt   # in the manifest, not in the bucket
LC_ALL=C comm -13 m.sorted l.sorted > extra.txt     # in the bucket, not in the manifest

On the same 100,000 keys this printed 137 and 83 and took 0.07 s including both sorts (5 runs, all 0.07 s). It does not see size changes; for those use the program below.

The comparison we used

python
def diff(manifest, listing):
    """Both iterators yield (key, size) in UTF-8 byte order; returns keys missing from the bucket,
    keys in the bucket that the manifest does not know, and keys whose size differs."""
    missing, extra, changed = [], [], []
    im, il = iter(manifest), iter(listing)
    m, l = next(im, None), next(il, None)
    while m is not None or l is not None:
        if l is None or (m is not None and m[0].encode() < l[0].encode()):
            missing.append(m[0]); m = next(im, None)
        elif m is None or l[0].encode() < m[0].encode():
            extra.append(l[0]); l = next(il, None)
        else:
            if m[1] != l[1]:
                changed.append(m[0])
            m, l = next(im, None), next(il, None)
    return missing, extra, changed

# the listing side, one page at a time (1,000 keys per request, UTF-8 byte order)
def listing(s3, bucket, prefix=""):
    for page in s3.get_paginator("list_objects_v2").paginate(Bucket=bucket, Prefix=prefix):
        for o in page.get("Contents", []):
            yield o["Key"], o["Size"]

The diff function is the one timed above. The paginator is the standard boto3 call and was not run for this article. Pointed at an S3-compatible endpoint, it needs <code>endpoint_url</code> and the usual keys; tport.space supports ListObjectsV2; we did not run the listing against it for this article.

Size is a weak check; what to add

  • A size match proves little: a truncated and a complete file of equal length are rare, a stale file of the same length is not. If the manifest carries MD5s, compare them to the ETag only for objects uploaded in one request; multipart ETags are not content hashes (Verifying a bucket copy compares size, ETag, MD5 and a full read).
  • Treat the 25 changed and 83 extra keys differently: extra keys may be deliberate (logs, thumbnails). Report them, do not delete them in the same pass.
  • For a migration run the diff once after the copy and once again after the final sync, then keep the two reports. The copy itself is covered in Migrating 50,000 files with rclone.

S3-compatible buckets with no egress fees: list, copy and check them with the tools you already use.

Create a bucket on tport.space

Test record and sources

  • Run on 2026-11-18 on a Mac mini (Apple M4), Python 3.12.9, macOS shell tools; no storage service was contacted. Data: 100,000 and 1,000,000 generated keys with planted faults (137, 83 and 25 per 100,000), listing pages in the ListObjectsV2 XML format. Results: 7 runs at 100,000 keys, 3 at 1,000,000 keys, every run checked against the planted answer.
  • Time per request in the sums is an assumed 0.3 s, not a measurement. Hash set memory in other languages was not measured.
  • Source: AWS, ListObjectsV2 (up to 1,000 keys per response, continuation token, keys in order).