viirya commented on PR #50327:
URL: https://github.com/apache/arrow/pull/50327#issuecomment-4861011814

   Good idea — I tried exactly that (`cdef list result = [None] * n` + indexed 
assignment, also letting null rows keep the prefilled `None`), but it 
benchmarks the same or slightly worse: `list<string>` 0.34 s → 0.35–0.37 s, 
`list<list<int32>>` 0.65 s → 0.69–0.70 s (best of 3, consistent across reruns).
   
   Two reasons, I think: Cython already lowers `result.append(x)` on a local it 
can see is a list to a `PyList_Append` call, and CPython lists over-allocate 
geometrically, so the resize cost is amortized and tiny. Meanwhile the 
preallocated version pays an extra refcount round-trip per slot (every 
`result[i] = x` has to decref the prefilled `None`). The loops are dominated by 
creating the per-row slice objects / decoding UTF-8 either way, so I kept the 
simpler `append` form.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to