tafia / calamine

A pure Rust Excel/OpenDocument SpreadSheets file reader: rust on metal sheets
MIT License
1.6k stars 155 forks source link

perf: pre-allocate buffers with `with_capacity()` #364

Closed RoloEdits closed 9 months ago

RoloEdits commented 9 months ago

Pre-allocating removes a lot of regrows for the buffers.

Benchmarks

Quick benchmark opening a 150k row, 17 column .xlsx file shows 15% increase in performance.

master:

868,545,530 ns/iter (+/- 7,365,438)

perf/pre_alloc_buf:

750,808,050 ns/iter (+/- 6,366,129)

Profiles

Purple highlight is alloc.

Current master: image

Change: image

Changed from vec![] macro to with_capacity() as there was an introduction to a lot of instructions running.

vec![0;N]: image

with_capacity(N): image

RoloEdits commented 9 months ago

Marginal improvement but still an improvement:

pre 2881d13: image

post: image

tafia commented 9 months ago

Awesome, thanks!