-
Notifications
You must be signed in to change notification settings - Fork 1
Implement T001 baseline benchmarks for application bootstrap and service lookup performance #56
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Copilot
wants to merge
2
commits into
001-baseline-specification-for
from
copilot/fix-1e87a6ed-c337-48f6-a515-b3bd0c899cba
Closed
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -0,0 +1,245 @@ | ||||||
| //go:build planned | ||||||
|
|
||||||
| // Package benchmark provides baseline performance benchmarks for the modular framework. | ||||||
| // | ||||||
| // This file implements Task T001: Baseline Benchmark as specified in the performance testing tasks spec. | ||||||
| // These benchmarks establish baseline performance metrics prior to dynamic reload & health aggregator implementations. | ||||||
| // | ||||||
| // Benchmarks included: | ||||||
| // - BenchmarkApplicationBootstrap: Measures application Build+Start time with mock modules | ||||||
| // - BenchmarkServiceLookup: Benchmarks repeated service lookup by interface/name | ||||||
| // | ||||||
| // All benchmarks are designed to be lightweight with no external network dependencies | ||||||
| // and minimal sleeps (<5ms) to ensure reliable and repeatable performance measurements. | ||||||
| package benchmark | ||||||
|
|
||||||
| import ( | ||||||
| "fmt" | ||||||
| "reflect" | ||||||
| "testing" | ||||||
|
|
||||||
| "github.com/GoCodeAlone/modular" | ||||||
| ) | ||||||
|
|
||||||
| // TestStorage is a simple interface for benchmarking service lookups | ||||||
| type TestStorage interface { | ||||||
| Store(key, value string) | ||||||
| Retrieve(key string) string | ||||||
| } | ||||||
|
|
||||||
| // MockStorage implements TestStorage for benchmarking | ||||||
| type MockStorage struct { | ||||||
| data map[string]string | ||||||
| } | ||||||
|
|
||||||
| func (m *MockStorage) Store(key, value string) { | ||||||
| if m.data == nil { | ||||||
| m.data = make(map[string]string) | ||||||
| } | ||||||
| m.data[key] = value | ||||||
| } | ||||||
|
|
||||||
| func (m *MockStorage) Retrieve(key string) string { | ||||||
| if m.data == nil { | ||||||
| return "" | ||||||
| } | ||||||
| return m.data[key] | ||||||
| } | ||||||
|
|
||||||
| // BenchmarkModule is a minimal module for benchmarking application bootstrap | ||||||
| type BenchmarkModule struct { | ||||||
| name string | ||||||
| serviceCount int | ||||||
| } | ||||||
|
|
||||||
| func (m *BenchmarkModule) Name() string { | ||||||
| return m.name | ||||||
| } | ||||||
|
|
||||||
| func (m *BenchmarkModule) Init(app modular.Application) error { | ||||||
| // Register multiple services to simulate realistic module behavior | ||||||
| for i := 0; i < m.serviceCount; i++ { | ||||||
| serviceName := fmt.Sprintf("%s-storage-%d", m.name, i) | ||||||
| storage := &MockStorage{data: make(map[string]string)} | ||||||
| storage.Store("benchmark", "value") | ||||||
|
|
||||||
| if err := app.RegisterService(serviceName, storage); err != nil { | ||||||
| return err | ||||||
| } | ||||||
| } | ||||||
| return nil | ||||||
| } | ||||||
|
|
||||||
| // TestLogger implements modular.Logger for benchmarking (minimal overhead) | ||||||
| type TestLogger struct{} | ||||||
|
|
||||||
| func (l *TestLogger) Debug(msg string, fields ...any) {} | ||||||
| func (l *TestLogger) Info(msg string, fields ...any) {} | ||||||
| func (l *TestLogger) Warn(msg string, fields ...any) {} | ||||||
| func (l *TestLogger) Error(msg string, fields ...any) {} | ||||||
| func (l *TestLogger) Logger() any { return l } | ||||||
|
|
||||||
| // BenchmarkApplicationBootstrap measures the time to build and start an application | ||||||
| // with multiple modules. This benchmark simulates realistic application startup. | ||||||
| func BenchmarkApplicationBootstrap(b *testing.B) { | ||||||
| b.ReportAllocs() | ||||||
|
|
||||||
| // Prepare configuration and logger outside the benchmark | ||||||
| cfg := &struct{}{} | ||||||
| configProvider := modular.NewStdConfigProvider(cfg) | ||||||
| logger := &TestLogger{} | ||||||
|
|
||||||
| b.ResetTimer() | ||||||
|
|
||||||
| for i := 0; i < b.N; i++ { | ||||||
| // Create application using builder pattern (Build + Start) | ||||||
| app, err := modular.NewApplication( | ||||||
| modular.WithConfigProvider(configProvider), | ||||||
| modular.WithLogger(logger), | ||||||
| modular.WithModules( | ||||||
| &BenchmarkModule{name: "module1", serviceCount: 3}, | ||||||
| &BenchmarkModule{name: "module2", serviceCount: 2}, | ||||||
| &BenchmarkModule{name: "module3", serviceCount: 1}, | ||||||
| ), | ||||||
| ) | ||||||
| if err != nil { | ||||||
| b.Fatalf("Failed to build application: %v", err) | ||||||
| } | ||||||
|
|
||||||
| // Initialize the application (equivalent to Build phase) | ||||||
|
||||||
| // Initialize the application (equivalent to Build phase) | |
| // Initialize the application (initialization phase after building) |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The documentation is incomplete - it mentions only 2 benchmarks but the file actually contains 3 benchmarks (including BenchmarkServiceLookupWithBatchRegistration). Update the comment to list all three benchmarks for accuracy.