Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CSV/TSV use a pool of buffered readers to avoid allocs #573

Merged
merged 2 commits into from
Aug 29, 2024

Conversation

gabriel-vasile
Copy link
Owner

use a pool of buffers to alleviate memory allocs in csv; related to #553

When iterating over multiple files, csv detector allocated a new buffer
for each file. This change adds a pool of buffers that can be reused
between detections. The same pool is shared between csv and tsv
detectors.

Benchmark results:

➜  magic git:(csvpprof) ✗ benchstat before after
goos: linux
goarch: amd64
pkg: github.com/gabriel-vasile/mimetype/internal/magic
cpu: Intel(R) Core(TM) i7-10510U CPU @ 1.80GHz
      │   before    │               after                │
      │   sec/op    │   sec/op     vs base               │
Csv-8   3.052µ ± 3%   1.695µ ± 3%  -44.46% (p=0.001 n=7)

      │    before    │                after                │
      │     B/op     │     B/op      vs base               │
Csv-8   5.258Ki ± 0%   1.164Ki ± 0%  -77.86% (p=0.001 n=7)

      │   before   │               after               │
      │ allocs/op  │ allocs/op   vs base               │
Csv-8   13.00 ± 0%   11.00 ± 0%  -15.38% (p=0.001 n=7)



When iterating over multiple files, csv detector allocated a new buffer
for each file. This change adds a pool of buffers that can be reused
between detections. The same pool is shared between csv and tsv
detectors.
@gabriel-vasile gabriel-vasile merged commit 4cc383c into master Aug 29, 2024
5 checks passed
@gabriel-vasile gabriel-vasile deleted the csvpprof branch August 29, 2024 14:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant