Follow-up to #809. A 16 KiB fixed stack buffer is a reasonable short-term compromise, but every compression call still reserves that full stack frame and larger inputs require a temporary heap buffer plus a copy.
Proposed solution: allocate the result bytes at 4 + LZ4_compressBound(input_size), compress directly into it, write the four-byte header, then shrink it to the exact compressed size with _PyBytes_Resize(). This removes the scratch stack buffer, avoids malloc/free, and eliminates the final copy. Benchmark against the 16 KiB stack implementation and document the CPython-private API tradeoff.
Follow-up to #809. A 16 KiB fixed stack buffer is a reasonable short-term compromise, but every compression call still reserves that full stack frame and larger inputs require a temporary heap buffer plus a copy.
Proposed solution: allocate the result bytes at
4 + LZ4_compressBound(input_size), compress directly into it, write the four-byte header, then shrink it to the exact compressed size with_PyBytes_Resize(). This removes the scratch stack buffer, avoidsmalloc/free, and eliminates the final copy. Benchmark against the 16 KiB stack implementation and document the CPython-private API tradeoff.