zip-rs / zip-old

Zip implementation in Rust
MIT License
731 stars 204 forks source link

Use some ::with_capacity when reading zip file. #303

Closed PJB3005 closed 2 years ago

PJB3005 commented 2 years ago

Now with a proper benchmark:

before:
test read_metadata ... bench:  11,988,380 ns/iter (+/- 1,411,339)
after:
test read_metadata ... bench:   9,600,650 ns/iter (+/- 804,604)

At this point most of the cost is memory allocations and hashmap inserts. You'd need a two-pass parser (one to get all file sizes to pre-allocate large buffers for the variable-length data, another to fill them) and that's far more complexity than I'd want to put effort in.

zamazan4ik commented 2 years ago

Could you please reformat your code?

PJB3005 commented 2 years ago

Just did