PLAIN/TEXT — ISSUE 405/456 COMPUTER SCIENCE · FOUNDATION / COMPUTER SCIENCE · ~4 MIN READING DATE: 2027-11-10 ARCHIVE: https://plaintext.click/newsletter/ SUBJECT: Why sorting a huge file is a data-moving problem Why sorting a huge file is a data-moving problem ================================================ / START HERE A file can be much larger than the memory available to sort it. External-memory sorting arranges data in order using both fast working memory and a larger, slower storage device. Its cost depends heavily on how often chunks of data must move between those places. / WHY NOW A sorting method that looks efficient when everything fits in memory can become painfully slow on a huge collection. Saving comparisons is not enough if it causes small, scattered reads from storage. / THE IDEA Working memory holds the part of the file the processor can manipulate directly. External storage supplies chunks called blocks. Reading one useful item can therefore bring in many neighbouring items at the same time, making sequential passes attractive. One approach first loads memory-sized chunks, sorts each chunk and writes the resulting sorted runs back to storage. It then merges runs by repeatedly choosing the smallest next item from their fronts. If enough front blocks fit in working memory, many runs can be merged in a single pass instead of repeatedly merging only pairs. / THE FORMAL IDEA one full read-and-write pass ≈ 2N/B block transfers - N = total number of records; B = records per transferred block. - N/B is the number of blocks when division is exact. Each pass reads and writes them once; transfers are counts, not elapsed seconds. / RUN THE TINY EXAMPLE Change one thing. Predict what happens. Let N = 1,000 records and B = 100 records per block. One read-and-write pass moves about 2 × 1,000/100 = 20 blocks. Initial run creation plus one merge pass costs about 40 transfers. Change to four merge passes after run creation: about 5 × 20 = 100 transfers. The file size did not change; the number of complete journeys through storage changed. More working memory can reduce how many merge passes are needed by accommodating more runs at once. That can save substantial traffic even without reducing the number of comparisons by the same proportion. / SO WHAT? When diagnosing a slow export, ask whether the data fit in memory and whether the software is reading sequentially or jumping between locations. A faster processor may sit waiting for blocks. Conversely, a storage-aware arrangement can make an unchanged processor finish sooner by keeping its data supplied efficiently. / ONE CAVEAT The example assumes full blocks and ignores startup, metadata, compression and overlap between calculation and transfers. Real devices have different sequential and random-access costs; the model isolates traffic rather than predicting an exact runtime. / KEEP THIS Once a dataset exceeds working memory, reduce full passes and scattered block transfers before assuming faster arithmetic will solve the bottleneck. / SOURCE TRAIL [1] NIST — External sort https://xlinux.nist.gov/dads/HTML/externalsort.html [2] MIT CSAIL — External-memory sorting https://jshun.csail.mit.edu/6506-f25/lectures/lecture6-2.pdf NEXT: How touching two silicon regions creates a barrier --- HARD IDEAS. PLAIN TEXT. You are receiving this because you asked for one clear computer-science or physics idea each day. Unsubscribe: https://plaintext.click/unsubscribe View in browser: https://plaintext.click/newsletter/2027/11/2027-11-10-external-sort-blocks.html From: Plain/Text / Brickston Consulting · 30 N Gould St Ste N, Sheridan, WY 82801 US · knowledge@plaintext.click