Skip to content

io: Return the pooled reader directly from bufferedReader - #70

Merged
bep merged 1 commit into
mainfrom
benchevanoberholsterimagemeta
Aug 8, 2026
Merged

io: Return the pooled reader directly from bufferedReader#70
bep merged 1 commit into
mainfrom
benchevanoberholsterimagemeta

Conversation

@bep

@bep bep commented Aug 8, 2026

Copy link
Copy Markdown
Owner

Let bytesAndReader implement readerCloser itself instead of wrapping it
in a closure and an anonymous struct per call. This cuts two allocations
per out-of-line EXIF tag value:

                                                               │    sec/op    │    sec/op      vs base              │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       17.58µ ± ∞ ¹    16.04µ ± ∞ ¹  -8.76% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10   2.629µ ± ∞ ¹    2.565µ ± ∞ ¹  -2.43% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     44.57µ ± ∞ ¹    44.71µ ± ∞ ¹       ~ (p=0.343 n=4)
geomean                                                          12.72µ          12.25µ        -3.70%
¹ need >= 6 samples for confidence interval at level 0.95

                                                               │  main.bench   │  benchevanoberholsterimagemeta.bench   │
                                                               │     B/op      │     B/op       vs base                 │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       4.422Ki ± ∞ ¹   2.965Ki ± ∞ ¹  -32.95% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10     549.0 ± ∞ ¹     501.0 ± ∞ ¹   -8.74% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     138.6Ki ± ∞ ¹   138.6Ki ± ∞ ¹        ~ (p=1.000 n=4) ²
geomean                                                          6.901Ki         5.859Ki        -15.10%
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal

                                                               │ main.bench  │ benchevanoberholsterimagemeta.bench  │
                                                               │  allocs/op  │  allocs/op   vs base                 │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       190.0 ± ∞ ¹   128.0 ± ∞ ¹  -32.63% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10   13.00 ± ∞ ¹   11.00 ± ∞ ¹  -15.38% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     816.0 ± ∞ ¹   816.0 ± ∞ ¹        ~ (p=1.000 n=4) ²
geomean                                                          126.3         104.7        -17.08%
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal

Co-Authored-By: Claude Fable 5 noreply@anthropic.com

Let bytesAndReader implement readerCloser itself instead of wrapping it
in a closure and an anonymous struct per call. This cuts two allocations
per out-of-line EXIF tag value:

```                                                               │  main.bench  │ benchevanoberholsterimagemeta.bench │
                                                               │    sec/op    │    sec/op      vs base              │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       17.58µ ± ∞ ¹    16.04µ ± ∞ ¹  -8.76% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10   2.629µ ± ∞ ¹    2.565µ ± ∞ ¹  -2.43% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     44.57µ ± ∞ ¹    44.71µ ± ∞ ¹       ~ (p=0.343 n=4)
geomean                                                          12.72µ          12.25µ        -3.70%
¹ need >= 6 samples for confidence interval at level 0.95

                                                               │  main.bench   │  benchevanoberholsterimagemeta.bench   │
                                                               │     B/op      │     B/op       vs base                 │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       4.422Ki ± ∞ ¹   2.965Ki ± ∞ ¹  -32.95% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10     549.0 ± ∞ ¹     501.0 ± ∞ ¹   -8.74% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     138.6Ki ± ∞ ¹   138.6Ki ± ∞ ¹        ~ (p=1.000 n=4) ²
geomean                                                          6.901Ki         5.859Ki        -15.10%
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal

                                                               │ main.bench  │ benchevanoberholsterimagemeta.bench  │
                                                               │  allocs/op  │  allocs/op   vs base                 │
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/alltags-10       190.0 ± ∞ ¹   128.0 ± ∞ ¹  -32.63% (p=0.029 n=4)
DecodeCompareWithGoexif/bep/imagemeta/exif/jpeg/orientation-10   13.00 ± ∞ ¹   11.00 ± ∞ ¹  -15.38% (p=0.029 n=4)
DecodeCompareWithGoexif/rwcarlsen/goexif/exif/jpg/alltags-10     816.0 ± ∞ ¹   816.0 ± ∞ ¹        ~ (p=1.000 n=4) ²
geomean                                                          126.3         104.7        -17.08%
¹ need >= 6 samples for confidence interval at level 0.95
² all samples are equal
````

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@codecov-commenter

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 78.95%. Comparing base (2289fdf) to head (1211d5c).

Additional details and impacted files
@@            Coverage Diff             @@
##             main      #70      +/-   ##
==========================================
+ Coverage   78.62%   78.95%   +0.33%     
==========================================
  Files          16       16              
  Lines        2129     2115      -14     
==========================================
- Hits         1674     1670       -4     
+ Misses        314      305       -9     
+ Partials      141      140       -1     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@bep
bep merged commit cdbb37f into main Aug 8, 2026
6 checks passed
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.

2 participants