Skip to content

Conversation

@abtreece
Copy link
Owner

Summary

  • Use sync.Pool to reuse the seen map in List() and ListDir() operations
  • Reduces allocations during high-frequency template processing (watch mode, short intervals)
  • Add benchmarks for List/ListDir operations

Changes

  • Add seenPool with initial capacity of 64 entries
  • Modify List() and ListDir() to get/put maps from pool
  • Use clear() builtin (Go 1.21+) to reset maps before returning to pool
  • Add 6 benchmarks covering basic, high-frequency, and large store scenarios

Benchmark Results

BenchmarkList-8                      96932    11395 ns/op    6594 B/op    102 allocs/op
BenchmarkList_HighFrequency-8        37704    31726 ns/op   19526 B/op    306 allocs/op
BenchmarkListDir-8                  107212    11246 ns/op    6594 B/op    102 allocs/op
BenchmarkListDir_HighFrequency-8     78188    15330 ns/op    8002 B/op    126 allocs/op
BenchmarkList_LargeStore-8            9544   121462 ns/op   65845 B/op   1002 allocs/op
BenchmarkListDir_LargeStore-8        10000   118759 ns/op   65846 B/op   1002 allocs/op

Test plan

  • All unit tests pass
  • Full test suite passes with race detection
  • Build succeeds
  • Benchmarks run successfully

Fixes #449

Use sync.Pool to reuse the seen map in List() and ListDir() operations,
reducing allocations during high-frequency template processing.

- Add seenPool with initial capacity of 64 entries
- Modify List() and ListDir() to get/put maps from pool
- Use clear() builtin (Go 1.21+) to reset maps before returning to pool
- Add benchmarks for List/ListDir operations

Fixes #449
Copilot AI review requested due to automatic review settings January 22, 2026 05:14
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR optimizes memory allocations in the memkv package by pooling the seen map used in List() and ListDir() operations. This reduces allocation overhead during high-frequency template processing scenarios like watch mode.

Changes:

  • Introduced sync.Pool for reusing seen maps with an initial capacity of 64 entries
  • Modified List() and ListDir() to acquire maps from the pool and return them after use
  • Added comprehensive benchmarks covering basic, high-frequency, and large store scenarios

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
pkg/memkv/store.go Added seenPool with sync.Pool and updated List()/ListDir() to use pooled maps
pkg/memkv/store_test.go Added benchmark helper function and 6 benchmark functions for List/ListDir operations

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.81%. Comparing base (b08730e) to head (b21b392).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #461      +/-   ##
==========================================
- Coverage   59.84%   59.81%   -0.03%     
==========================================
  Files          48       48              
  Lines        5294     5305      +11     
==========================================
+ Hits         3168     3173       +5     
- Misses       1917     1923       +6     
  Partials      209      209              

☔ View full report in Codecov by Sentry.
📢 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.

- Extract seenPoolCapacity constant with documentation explaining the
  choice of 64 as initial capacity
- Fix setupBenchmarkStore to create exactly numKeys keys regardless
  of divisibility by 10
@abtreece abtreece merged commit 096fd63 into main Jan 22, 2026
11 checks passed
@abtreece abtreece deleted the perf/pool-map-allocations-449 branch January 22, 2026 05:19
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.

Pool map allocations in memkv List/ListDir operations

1 participant