Skip to content

Conversation

@abtreece
Copy link
Owner

Summary

  • Cache the result of util.AppendPrefix() on TemplateResource initialization to avoid repeated computation on every process() cycle
  • Add prefixedKeys field to TemplateResource struct computed once during initialization
  • Update backendFetcher to store and use pre-computed prefixed keys
  • Change fetchValues() signature to use stored keys instead of parameter

Test plan

  • Unit tests pass (go test ./...)
  • Build succeeds (make build)
  • Integration tests (requires backend services)

Fixes #445

🤖 Generated with Claude Code

Cache the result of util.AppendPrefix() on TemplateResource initialization
to avoid repeated computation on every process() cycle.

Changes:
- Add prefixedKeys field to TemplateResource struct
- Compute prefixedKeys once in NewTemplateResource after normalizing prefix
- Update backendFetcher to store and use pre-computed prefixedKeys
- Change fetchValues() signature to use stored keys instead of parameter
- Update processor.go and preflight.go to use cached prefixedKeys

Fixes #445
Copilot AI review requested due to automatic review settings January 22, 2026 04:06
@codecov
Copy link

codecov bot commented Jan 22, 2026

Codecov Report

❌ Patch coverage is 83.33333% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 59.80%. Comparing base (ea56f0f) to head (5a06a59).
⚠️ Report is 1 commits behind head on main.

Files with missing lines Patch % Lines
pkg/template/processor.go 50.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #457      +/-   ##
==========================================
- Coverage   59.82%   59.80%   -0.02%     
==========================================
  Files          48       48              
  Lines        5244     5244              
==========================================
- Hits         3137     3136       -1     
- Misses       1901     1902       +1     
  Partials      206      206              

☔ 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.

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 template processing by caching prefixed keys at initialization time rather than computing them repeatedly during each process cycle. This addresses performance issue #445 by eliminating redundant util.AppendPrefix() calls.

Changes:

  • Add prefixedKeys field to TemplateResource struct, computed once during initialization
  • Update backendFetcher to store and use pre-computed prefixed keys
  • Remove keys parameter from fetchValues() method signature

Reviewed changes

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

Show a summary per file
File Description
pkg/template/resource.go Add prefixedKeys field and compute it during initialization; pass to backend fetcher
pkg/template/processor.go Replace repeated util.AppendPrefix() calls with cached prefixedKeys field
pkg/template/preflight.go Use cached prefixedKeys instead of computing on-demand
pkg/template/backend_fetcher.go Store prefixed keys and remove parameter from fetchValues()
pkg/template/backend_fetcher_test.go Update test cases to provide PrefixedKeys in config

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

Gid int
Group string
Keys []string
prefixedKeys []string // Cached keys with prefix applied
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The field prefixedKeys should follow Go naming conventions and be exported as PrefixedKeys since it's being passed to other packages (e.g., in backendFetcherConfig). Alternatively, if it should remain unexported, the backendFetcherConfig.PrefixedKeys field should also be unexported.

Copilot uses AI. Check for mistakes.
storeClient backends.StoreClient
store *memkv.Store
prefix string
prefixedKeys []string // Pre-computed keys with prefix applied
Copy link

Copilot AI Jan 22, 2026

Choose a reason for hiding this comment

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

The field prefixedKeys is unexported but receives data from an exported field PrefixedKeys in the config struct. For consistency, either both should be exported or both should be unexported.

Copilot uses AI. Check for mistakes.
@abtreece abtreece merged commit 57ad7f2 into main Jan 22, 2026
11 checks passed
@abtreece abtreece deleted the cache-prefixed-keys branch January 22, 2026 04:09
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.

Cache prefixed keys on template resource initialization

1 participant