Amortized Work and Per-Operation Latency
Turn a resize spike into bounded background copying and account for accesses while two arrays coexist.
- Source
- Anbloq
- Language
- English
- Created
- Updated
- Chapters
- 2
- Reading time
- 1 min
In this article2 chapters
Averages permit a long individual operation
A growing array can append with constant amortized work while one resize copies a million records. A caller with a fixed deadline cares about that single append. The cost guarantee needed is worst-case local work, or a statistical bound under an explicit workload. Either measure asks for more than the total work used in the standard amortized proof.
Schedule migration before the next boundary
With old capacity \(n\) and a new buffer of capacity \(2n\), retain old elements temporarily and place new appends in the new buffer. Copy a bounded number of old slots per append. A monotone copy frontier suffices if the copied prefix is routed to the new buffer and the uncopied suffix to the old one. Overwrites must reach the authoritative location. After \(n\) appends, moving at least one old element per append has completed the migration. The memory allocator and concurrent readers still need their own bounds. Memory reclamation explains when a retired buffer can be freed in a concurrent variant.[1][2]