Skip to content

Conversation

goccy
Copy link
Member

@goccy goccy commented Sep 4, 2025

No description provided.

@Copilot Copilot AI review requested due to automatic review settings September 4, 2025 01:45
Copy link

@Copilot 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 pull request implements instance pooling for CEL plugins, allowing multiple instances to be created and reused to improve performance and concurrency handling.

  • Introduces a CELPluginInstancePool with LRU cache and TTL-based expiration for managing plugin instances
  • Refactors the service generation to use plugin references instead of single instances
  • Adds context-based instance management with proper cleanup mechanisms

Reviewed Changes

Copilot reviewed 10 out of 12 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
grpc/federation/cel/plugin.go Main implementation of instance pooling with LRU cache and context management
go.mod Adds hashicorp/golang-lru/v2 dependency for LRU cache functionality
generator/templates/server.go.tmpl Updates template to use plugin references and context-based instance management
_examples/18_load/proto/plugin/plugin.proto Adds network capability configuration to example
_examples/18_load/plugin/plugin_grpc_federation.pb.go Generated code with network transport initialization
_examples/18_load/plugin/plugin.pb.go Updated protobuf generated code
_examples/18_load/main_test.go Test fixes for goroutine leak detection
_examples/18_load/go.mod Dependency updates for example
_examples/18_load/federation/federation_grpc_federation.pb.go Generated federation service code with new pooling
_examples/18_load/compose.yaml Docker compose configuration for testing

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment on lines +107 to 115
if cache := getCompilationCache(cfg.Name, cfg.CacheDir); cache != nil {
runtimeCfg = runtimeCfg.WithCompilationCache(cache)
}
} else {
runtimeCfg = wazero.NewRuntimeConfig()
if cache := getCompilationCache(cfg.Name, cfg.CacheDir); cache != nil {
runtimeCfg = runtimeCfg.WithCompilationCache(cache)
}
}
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

The compilation cache is being set when cfg.CacheDir is empty, but getCompilationCache will return nil when baseDir (cfg.CacheDir) is empty and no temp directory is available. This creates inconsistent behavior between the two branches.

Suggested change
if cache := getCompilationCache(cfg.Name, cfg.CacheDir); cache != nil {
runtimeCfg = runtimeCfg.WithCompilationCache(cache)
}
} else {
runtimeCfg = wazero.NewRuntimeConfig()
if cache := getCompilationCache(cfg.Name, cfg.CacheDir); cache != nil {
runtimeCfg = runtimeCfg.WithCompilationCache(cache)
}
}
} else {
runtimeCfg = wazero.NewRuntimeConfig()
}
if cache := getCompilationCache(cfg.Name, cfg.CacheDir); cache != nil {
runtimeCfg = runtimeCfg.WithCompilationCache(cache)
}

Copilot uses AI. Check for mistakes.

Comment on lines +183 to +188
pool.cache = expirable.NewLRU(1, func(_ *CELPluginInstance, v *CELPluginInstance) {
if _, exists := pool.guardMap.Load(v); exists {
return
}
v.Close()
}, 1*time.Minute)
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The magic number 1 for initial LRU size and 1*time.Minute for TTL should be configurable constants. Hard-coding these values makes the pooling behavior difficult to tune for different use cases.

Copilot uses AI. Check for mistakes.

Comment on lines +215 to +220
if noCap := p.cache.Add(v, v); noCap {
// grow cache capacity.
p.cache.Resize(p.cache.Len() * 2)
p.cache.Add(v, v)
//fmt.Println("grow length", p.cache.Len())
}
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

[nitpick] The cache growth strategy using p.cache.Len() * 2 could lead to unbounded memory usage. Consider implementing a maximum cache size limit to prevent excessive memory consumption.

Copilot uses AI. Check for mistakes.

_, removed, ok := p.cache.RemoveOldest()
p.guardMap.Delete(oldest)
if oldest == removed && ok {
//fmt.Printf("get: %p\n", removed)
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Remove commented debug print statements from production code. These should be removed or converted to proper logging if needed for debugging.

Copilot uses AI. Check for mistakes.

}
}
ret, err := p.fn()
//fmt.Printf("new: %p\n", ret)
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Remove commented debug print statements from production code. These should be removed or converted to proper logging if needed for debugging.

Copilot uses AI. Check for mistakes.

// grow cache capacity.
p.cache.Resize(p.cache.Len() * 2)
p.cache.Add(v, v)
//fmt.Println("grow length", p.cache.Len())
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Remove commented debug print statements from production code. These should be removed or converted to proper logging if needed for debugging.

Suggested change
//fmt.Println("grow length", p.cache.Len())

Copilot uses AI. Check for mistakes.

func (p *CELPlugin) ReleaseInstance(instance *CELPluginInstance) {
instance.enqueueGC()
p.instancePool.Put(instance)
//fmt.Printf("put: %p\n", instance)
Copy link
Preview

Copilot AI Sep 4, 2025

Choose a reason for hiding this comment

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

Remove commented debug print statements from production code. These should be removed or converted to proper logging if needed for debugging.

Suggested change
//fmt.Printf("put: %p\n", instance)

Copilot uses AI. Check for mistakes.

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