Skip to content

v2.1.1 - #11

Merged
chanido merged 13 commits into
masterfrom
develop
Oct 13, 2025
Merged

chanido merged 13 commits into
masterfrom
develop

Conversation

@chanido

@chanido chanido commented Oct 13, 2025

Copy link
Copy Markdown
Owner

Improving memory statistics stimations

chanido and others added 10 commits August 11, 2025 15:52
Replaces a fixed time-based wait with a conditional wait for eviction completion to make tests deterministic.
Reduces flakiness and can shorten runtime by proceeding immediately once evictions occur.
- Implemented coverage tests for various size computation modes: Balanced, Fast, Adaptive, and Accurate.
- Added tests for null and primitive types, enums, arrays, collections, and complex nested structures.
- Included edge cases and cycle detection tests to ensure robustness.
- Verified size calculations for anonymous types and custom structs.
- Ensured consistent results across repeated calls and different modes.
Copilot AI review requested due to automatic review settings October 13, 2025 09:40

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves memory statistics estimations and introduces performance optimizations for BlitzCache v2.1.1. The update focuses on enabling zero-overhead operation when statistics tracking features are disabled and improving the accuracy of memory size calculations.

  • Enhanced memory sizing with configurable computation modes and improved object graph traversal
  • Zero-overhead conditional statistics when tracking features are disabled
  • Deterministic capacity enforcement with better eviction accounting

Reviewed Changes

Copilot reviewed 40 out of 41 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
README.md Updated documentation with new zero-overhead features and configuration options
CHANGELOG.md Added v2.1.1 release notes detailing performance improvements
BlitzCache/Statistics/Speed/* Reorganized statistics classes into Speed namespace
BlitzCache/Statistics/Memory/* New memory sizing infrastructure with multiple computation modes
BlitzCache/Statistics/CacheStatistics.cs Added conditional size tracking and external removal handling
BlitzCache/Capacity/* New capacity enforcement system with configurable eviction strategies
BlitzCache/BlitzCacheOptions.cs Configuration options class for future-proof setup
BlitzCache/Extensions/IServiceCollectionExtensions.cs Enhanced DI registration with options pattern support
BlitzCache/Logging/* Improved logging to omit disabled tracking sections
BlitzCache.Tests/* Comprehensive test coverage for new features

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

Comment thread BlitzCache/Statistics/Speed/SlowQuery.cs Outdated
{
var ft = f.FieldType;
object? fv = null;
try { fv = f.GetValue(obj); } catch { }

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

Empty catch blocks suppress all exceptions without logging. Consider logging reflection failures or catching specific exception types (like TargetParameterCountException) for better debugging.

Suggested change
try { fv = f.GetValue(obj); } catch { }
try { fv = f.GetValue(obj); }
catch (Exception ex)
{
// Log reflection failure for debugging
Console.Error.WriteLine($"Failed to get value for field '{f.Name}' on type '{obj?.GetType().FullName}': {ex}");
}

Copilot uses AI. Check for mistakes.
{
var ft = f.FieldType;
object? fv = null;
try { fv = f.GetValue(structValue); } catch { }

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

Empty catch blocks suppress all exceptions without logging. Consider logging reflection failures or catching specific exception types (like TargetParameterCountException) for better debugging.

Suggested change
try { fv = f.GetValue(structValue); } catch { }
try { fv = f.GetValue(structValue); }
catch (Exception ex)
{
// Log reflection failure for debugging
Console.Error.WriteLine($"Failed to get value for field '{f.Name}' of type '{type.FullName}': {ex.GetType().Name}: {ex.Message}");
}

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +85
long total = _options.ObjectHeaderSize;
var mode = _options.Mode;
bool isAdaptive = mode == SizeComputationMode.Adaptive;
bool isAccurate = mode == SizeComputationMode.Accurate;
int effectiveMaxDepth = _options.MaxDepth + (isAccurate ? 1 : 0);
if (isAdaptive) effectiveMaxDepth = _options.MaxDepth; // bounded strictly below Accurate

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

The effectiveMaxDepth calculation logic is complex with mode-specific overrides. Consider extracting this into a separate method like CalculateEffectiveMaxDepth(mode, maxDepth) for better readability and testability.

Copilot uses AI. Check for mistakes.
internal void OnExternalRemoval(string cacheKey, long sizeBytes, bool countAsEviction)
{
// Mark so eviction callback can short-circuit.
externallyRemoved[cacheKey] = 0;

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

Using 0 as a sentinel value in the ConcurrentDictionary is unclear. Consider using a more descriptive approach like externallyRemoved.TryAdd(cacheKey, true) or a dedicated marker value for better code clarity.

Suggested change
externallyRemoved[cacheKey] = 0;
externallyRemoved[cacheKey] = true;

Copilot uses AI. Check for mistakes.
Comment on lines +50 to +51
var heaviestProp = cacheStatsType.GetProperty("HeaviestTrackingEnabled", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);
var slowestProp = cacheStatsType.GetProperty("SlowestTrackingEnabled", BindingFlags.NonPublic | BindingFlags.Instance | BindingFlags.Public);

Copilot AI Oct 13, 2025

Copy link

Choose a reason for hiding this comment

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

Reflection calls in the logging path on every log operation can impact performance. Consider caching the PropertyInfo objects or using a static detection approach during logger initialization.

Copilot uses AI. Check for mistakes.
@chanido
chanido merged commit a982f95 into master Oct 13, 2025
17 of 18 checks passed
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.

4 participants