Use xFetch() to access temporary files in vdbesort.c. Use a single large allocation instead of many small allocations when accumulating records in vdbesort.c. This is an interim commit - it allocates a buffer the size of the page-cache every time data is sorted.
Instead of allocating a single large buffer at the beginning of each sort operation, start with a small buffer and extend it using realloc() as required.