apache / fury

A blazingly fast multi-language serialization framework powered by JIT and zero-copy.
https://fury.apache.org/
Apache License 2.0
3.11k stars 248 forks source link

perf(python): Pre-allocate size for the dictionary #1949

Closed penguin-wwy closed 2 days ago

penguin-wwy commented 2 days ago

What does this PR do?

Pre-allocate memory for the dictionary based on the data size to avoid resizing and improve deserialization performance.

Related issues

Does this PR introduce any user-facing change?

Benchmark

# python format
fury_large_dict: Mean +- std dev: [dict_base] 548 us +- 33 us -> [dict_resize] 531 us +- 33 us: 1.03x faster

# xlang format
fury_large_dict: Mean +- std dev: [dict_xlang_base] 550 us +- 39 us -> [dict_xlang_resize] 527 us +- 35 us: 1.05x faster