Performance Optimizations and Test Suite#56
Merged
Conversation
This commit introduces significant improvements to testing coverage, fixes critical bugs, and optimizes performance. Performance Optimizations: - Switch default level cache from array to sync.Map for lock-free reads - Add per-target level caching to reduce repeated filter checks - Reduce memory footprint (array cache uses 524KB vs sparse sync.Map) - Benchmarks show improved performance under concurrent load Critical Bug Fixes: - Fix deadlock in ResetLevelCache when called from AddTarget/RemoveTargets - Fix nil pointer dereference in syncMapLevelCache.get() for missing keys - Fix race condition in target shutdown sequence Test Suite Additions (85+ new tests): - Buffer pool tests: reuse, concurrency, memory leaks, integration - Concurrent operation tests: logging, flushing, target management - Error handling tests: invalid fields, queue overflow, shutdown - Filter tests: custom filters, level boundaries, mixed filters - Level cache tests: invalidation, concurrency, backward compatibility - Logger tests: WithFields, structured logging, context propagation - LogM tests: multi-level logging, mixed filters, cache behavior - Queue tests: overflow, concurrent operations, flush behavior Development Tooling: - Add .golangci.yml for consistent linting - Add Makefile with common development tasks - Update README with performance guidance All tests passing with no race conditions detected.
There was a problem hiding this comment.
Pull Request Overview
This PR implements performance optimizations and adds a comprehensive test suite for the logging system as groundwork for an upcoming tag-based filtering system. The changes focus on making the sync.Map level cache the default, adding per-target caching, and optimizing string quoting logic for better performance.
Key changes:
- Switch from arrayLevelCache to syncMapLevelCache as default for better performance with sparse level IDs
- Add per-target level caching to eliminate redundant filter checks during fanout operations
- Optimize shouldQuote() function with early-exit logic for faster string processing
Reviewed Changes
Copilot reviewed 34 out of 34 changed files in this pull request and generated no comments.
Show a summary per file
| File | Description |
|---|---|
| options.go | Changes cache defaults and updates option naming for backward compatibility |
| logr.go | Implements cache default switch and improves cache invalidation with lock ordering |
| target.go | Adds per-target level caching infrastructure |
| formatter.go | Optimizes shouldQuote() function with early-exit boolean logic |
| levelcache.go | Fixes potential nil panic in syncMapLevelCache.get() |
| test files | Adds comprehensive test coverage across multiple scenarios |
| config files | Adds configuration schema, documentation, and build automation |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
davidkrauser
approved these changes
Nov 4, 2025
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
This PR lays the groundwork for the upcoming tag-based filtering system (see docs/TAGGING-DESIGN.md) by implementing critical performance optimizations and comprehensive test coverage.
Performance Optimizations (~3-4x improvement: 640ns → 200ns per log call)
Bug Fixes
Comprehensive Test Suite (3,900+ lines, 85+ new tests)
Documentation & Tooling
Ticket Link
NONE