/ 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.
|
NEXT: How touching two silicon regions creates a barrier
|