Skip to content

Modernize APIs and speed up slice codecs#24

Merged
kelindar merged 6 commits into
masterfrom
modernize
Jul 20, 2026
Merged

Modernize APIs and speed up slice codecs#24
kelindar merged 6 commits into
masterfrom
modernize

Conversation

@kelindar

@kelindar kelindar commented Jul 20, 2026

Copy link
Copy Markdown
Owner

Summary

  • Apply gopls modernize suggestions across the module (any, range-over-int, reflect.TypeFor, drop obsolete +build line)
  • Fix reflect.SliceHeader vet warnings without regressing nocopy zero-copy decode
  • Speed up slice decode (capacity reuse), varint batch encodes, and sorted integer codecs

Benchmarks

name                 time/op      ops/s        allocs/op    vs prev           
-------------------- ------------ ------------ ------------ ------------------
binary/enc           124.1 ns     8.1M         🟰 2          ✅ +15%                               
binary/enc-to        91.0 ns      11.0M        🟰 0          ✅ +14%                               
binary/dec           94.5 ns      10.6M        ✅ 1          ✅ +78%                               
binary/map-enc       8.1 µs       123.3K       ✅ 209        ✅ +14%                               
binary/map-dec       12.4 µs      80.4K        ✅ 500        ✅ +12%                               
binary/slice-enc     8.5 µs       118.1K       🟰 9          ✅ +7%                                
binary/slice-dec     6.9 µs       145.2K       ✅ 100        ✅ +2.1x                              
binary/nest-enc      4.4 µs       227.2K       ✅ 13         ✅ +9%                                
binary/nest-dec      3.8 µs       260.2K       ✅ 63         ✅ +2.1x                              
binary/bytes-enc     823.4 ns     1.2M         🟰 3          🟰 similar                            
binary/bytes-dec     166.3 ns     6.0M         ✅ 0          ✅ +5.0x                              
binary/u64-enc       37.7 µs      26.5K        ✅ 3          ✅ +87%                               
binary/u64-dec       55.5 µs      18.0K        ✅ 0          🟰 similar                            
binary/reuse-enc     90.6 ns      11.0M        🟰 0          ✅ +22%                               
binary/stream-dec    143.1 ns     7.0M         ✅ 1          ✅ +72%                               
nocopy/str-enc       103.1 ns     9.7M         🟰 3          ✅ +7%                                
nocopy/str-dec       32.1 ns      31.2M        🟰 0          ✅ +17%                               
nocopy/dict-enc      178.6 ns     5.6M         🟰 2          🟰 similar                            
nocopy/dict-dec      147.2 ns     6.8M         🟰 2          🟰 similar                            
nocopy/bmap-enc      312.5 ns     3.2M         🟰 5          🟰 similar                            
nocopy/bmap-dec      153.6 ns     6.5M         🟰 2          🟰 similar                            
nocopy/hmap-enc      307.1 ns     3.3M         🟰 5          🟰 similar                            
nocopy/hmap-dec      138.5 ns     7.2M         🟰 2          🟰 similar                            
nocopy/bytes-enc     848.7 ns     1.2M         🟰 3          🟰 similar                            
nocopy/bytes-dec     34.0 ns      29.4M        🟰 0          ✅ +22%                               
nocopy/u64-enc       5.2 µs       192.6K       🟰 3          🟰 similar                            
nocopy/u64-dec       30.8 ns      32.5M        🟰 0          ✅ +23%                               
nocopy/col-enc       482.9 ns     2.1M         ✅ 8          ✅ +8%                                
nocopy/col-dec       344.4 ns     2.9M         ✅ 6          ✅ +41%                               
nocopy/struct-enc    155.8 ns     6.4M         🟰 3          🟰 similar                            
nocopy/struct-dec    69.5 ns      14.4M        🟰 0          ✅ +12%                               
sorted/i32-enc       79.4 µs      12.6K        🟰 5          🟰 similar                            
sorted/i32-dec       55.5 µs      18.0K        ✅ 0          ✅ +9.9x                              
sorted/u32-enc       75.6 µs      13.2K        🟰 5          🟰 similar                            
sorted/u32-dec       49.3 µs      20.3K        ✅ 0          ✅ +11x                               
sorted/ts-enc        49.3 µs      20.3K        🟰 6          🟰 similar                            
sorted/ts-dec        21.8 µs      45.9K        🟰 2          🟰 similar                            
sorted/tsz-enc       125.7 µs     8.0K         🟰 7          🟰 similar                            
sorted/tsz-dec       116.6 µs     8.6K         🟰 3          🟰 similar                            
sorted/tcz-enc       87.0 µs      11.5K        🟰 6          ✅ +95%                               
sorted/tcz-dec       76.2 µs      13.1K        🟰 3          ✅ +51%                               
unsafe/u64-enc       471.9 ns     2.1M         🟰 3          🟰 similar                            
unsafe/u64-dec       447.7 ns     2.2M         🟰 2          🟰 similar    

Test plan

  • go test ./... passes
  • go vet ./... is clean
  • cd bench && go run . looks consistent with the numbers above

Replace interface{} with any, use range-over-int and reflect.TypeFor,
and drop the obsolete +build line now that the module requires Go 1.25.

Co-authored-by: Cursor <cursoragent@cursor.com>
@github-actions

github-actions Bot commented Jul 20, 2026

Copy link
Copy Markdown
96.0%

passed

███████████████████░96.0% on changed lines

172 lines changed   6 uncovered   10 files

 📂 10 files changed
File Coverage Uncovered Lines
🟡 decoder.go 84.6% 58, 59

| 🟡 | encoder.go | 85.7% | 81, 82 |

| 🟢 | codecs.go | 96.7% | 212, 250 |

| 🟢 | nocopy/types.go | 100.0% | — |

| 🟢 | sorted/codecs.go | 100.0% | — |

| 🟢 | sorted/types.go | 100.0% | — |

| 🟢 | unsafe/types.go | 100.0% | — |

| 🟢 | scanner.go | 100.0% | — |

| 🟢 | sorted/timeseries.go | 100.0% | — |

| 🟢 | convert.go | 100.0% | — |

 📋 Full diff-cover report

Diff Coverage

Diff: origin/master...HEAD, staged and unstaged changes

  • codecs.go (96.7%): Missing lines 212,250
  • convert.go (100%)
  • decoder.go (84.6%): Missing lines 58-59
  • encoder.go (85.7%): Missing lines 81-82
  • nocopy/types.go (100%)
  • scanner.go (100%)
  • sorted/codecs.go (100%)
  • sorted/timeseries.go (100%)
  • sorted/types.go (100%)
  • unsafe/types.go (100%)

Summary

  • Total: 172 lines
  • Missing: 6 lines
  • Coverage: 96%

codecs.go

  208 		}
  209 		e.Write(buffer)
  210 		return
  211 	}
! 212 	for i := range l {
  213 		e.WriteVarint(rv.Index(i).Int())
  214 	}
  215 	return
  216 }

  246 		}
  247 		e.Write(buffer)
  248 		return
  249 	}
! 250 	for i := range l {
  251 		e.WriteUvarint(rv.Index(i).Uint())
  252 	}
  253 	return
  254 }

decoder.go

  54 	t := rv.Type()
  55 	c := d.codec
  56 	if t != d.last {
  57 		if c, err = scan(t); err != nil {
! 58 			return
! 59 		}
  60 		d.last = t
  61 		d.codec = c
  62 	}
  63 	err = c.DecodeTo(d, rv)

encoder.go

  77 	t := rv.Type()
  78 	c := e.codec
  79 	if t != e.last {
  80 		if c, err = scan(t); err != nil {
! 81 			return
! 82 		}
  83 		e.last = t
  84 		e.codec = c
  85 	}

🛡️ diff-cover-action

@coveralls

coveralls commented Jul 20, 2026

Copy link
Copy Markdown

Coverage Report for CI Build 29774811568

Coverage decreased (-0.3%) to 91.578%

Details

  • Coverage decreased (-0.3%) from the base build.
  • Patch coverage: 6 uncovered changes across 3 files (166 of 172 lines covered, 96.51%).
  • 6 coverage regressions across 1 file.

Uncovered Changes

File Changed Covered %
codecs.go 61 59 96.72%
decoder.go 13 11 84.62%
encoder.go 14 12 85.71%
Total (10 files) 172 166 96.51%

Coverage Regressions

6 previously-covered lines in 1 file lost coverage.

File Lines Losing Coverage Coverage
codecs.go 6 92.36%

Coverage Stats

Coverage Status
Relevant Lines: 1591
Covered Lines: 1457
Line Coverage: 91.58%
Coverage Strength: 626.3 hits per line

💛 - Coveralls

kelindar and others added 3 commits July 20, 2026 20:15
Replace deprecated SliceHeader/StringHeader casting with unsafe.Slice
and unsafe.StringData so go vet stays clean on Go 1.25.

Co-authored-by: Cursor <cursoragent@cursor.com>
rv.Set(reflect.NewAt(...)) allocated on decode and regressed
nocopy/u64-dec. Mutate the slice header in place again without
using deprecated reflect.SliceHeader.

Co-authored-by: Cursor <cursoragent@cursor.com>
Reuse slice capacity on decode, batch varint writes into bytes.Buffer,
and decode sorted integer slices without reflect.Append so hot paths
allocate less and run faster.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kelindar kelindar changed the title Apply gopls modernize fixes Modernize APIs and speed up slice codecs Jul 20, 2026
kelindar and others added 2 commits July 20, 2026 21:00
Remove vs-ref (JSON and safe baselines) so benches only report absolute
timing and vs-prev deltas.

Co-authored-by: Cursor <cursoragent@cursor.com>
@kelindar
kelindar enabled auto-merge (squash) July 20, 2026 20:07
@kelindar
kelindar merged commit dfcd154 into master Jul 20, 2026
1 check passed
@kelindar
kelindar deleted the modernize branch July 20, 2026 20:08
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