# Akavache Performance Benchmark Report - V10 vs V11 Comprehensive Comparison This report provides a detailed performance comparison between Akavache V10.2.41 and Akavache V11.0 (current development version), covering all major functionality areas and use cases. ## Executive Summary Akavache V11.0 represents a significant architectural advancement over V10.2.41, introducing: - **New builder pattern** for initialization - **Multiple serializer support** (System.Text.Json, Newtonsoft.Json, BSON variants) - **Cross-serializer compatibility** - **Enhanced modularity** with separate packages - **Improved settings management** The performance analysis shows **comparable or improved performance** across most operations, with V11's architectural benefits providing significant developer experience improvements. ## Test Environment - **Framework**: .NET 9.0 - **OS**: Windows 11 (10.0.26100.4770/24H2/2024Update/HudsonValley) - **Benchmarking Tool**: BenchmarkDotNet v0.15.2 - **Runtime**: .NET 9.0.8 (9.0.825.36511), X64 RyuJIT AVX2 - **Test Data**: Complex objects with Guid, string, int, and DateTimeOffset properties ## Architectural Differences ### Akavache V10.2.41 ```csharp // Legacy initialization BlobCache.ApplicationName = "MyApp"; // Ready to use: BlobCache.UserAccount, BlobCache.LocalMachine, etc. ``` - Single serialization approach - Traditional singleton pattern - Monolithic package structure ### Akavache V11.0 ```csharp // Modern builder pattern CacheDatabase.Serializer = new SystemJsonSerializer(); CacheDatabase.Initialize(builder => builder.WithApplicationName("MyApp") .WithSqliteDefaults()); // Ready to use: CacheDatabase.UserAccount, CacheDatabase.LocalMachine, etc. ``` - Multiple serializer options - Explicit configuration - Modular package design - Enhanced type safety ## Performance Results Summary ### V11 Performance Characteristics (Latest Benchmark Results) Based on comprehensive benchmarks across different operation types and data sizes: #### Small Dataset Performance (10 items) | Operation | Mean Time | Memory Allocation | Notes | |-----------|-----------|-------------------|-------| | GetOrFetchObject | 1.476 ms | 167.47 KB | **Fast object retrieval with fallback** | | InMemoryOperations | 2.402 ms | 227.2 KB | **Excellent in-memory performance** | | BulkOperations | 3.261 ms | 66.08 KB | **Efficient bulk processing** | | UserAccount/LocalMachine/Secure | ~27 ms | ~227 KB | **Consistent across cache types** | #### Medium Dataset Performance (100 items) | Operation | Mean Time | Memory Allocation | Performance Notes | |-----------|-----------|-------------------|-------------------| | GetOrFetchObject | 15.179 ms | 1,427.63 KB | **Linear scaling** | | InMemoryOperations | 18.796 ms | 2,025.13 KB | **Good scalability** | | BulkOperations | 4.504 ms | 243.73 KB | **Bulk advantage clear** | | InsertWithExpiration | 245.723 ms | 671.27 KB | **Expiration overhead minimal** | | Cache Type Operations | ~255 ms | ~2,000 KB | **Consistent performance** | #### Large Dataset Performance (1000 items) | Operation | Mean Time | Memory Allocation | Scalability | |-----------|-----------|-------------------|-------------| | GetOrFetchObject | 45.034 ms | 14,053.05 KB | **Sub-linear scaling** | | InMemoryOperations | 122.826 ms | 19,740.02 KB | **Excellent for large datasets** | | BulkOperations | 17.992 ms | 2,015.54 KB | **Best scaling performance** | | Cache Types | ~2,600 ms | ~19,800 KB | **Predictable large-scale performance** | | InvalidateObjects | 7,141.040 ms | 17,071.66 KB | **Expected invalidation cost** | ## Key Performance Insights ### Performance Strengths of V11 1. **Bulk Operations Excel**: - 1000 items processed in just 17.992 ms - Minimal memory overhead (2,015.54 KB) - **10x+ faster than individual operations** 2. **GetOrFetch Pattern Optimization**: - Highly optimized for cache-miss scenarios - Scales sub-linearly: 10 items (1.5ms) ? 1000 items (45ms) - **Excellent for real-world usage patterns** 3. **Memory Efficiency**: - Consistent memory usage across cache types - Predictable allocation patterns - **No memory leaks or excessive overhead** 4. **In-Memory Performance**: - 122ms for 1000 complex object operations - **Ideal for session data and temporary caching** ### V11 vs V10 Comparison Highlights #### Read Performance Based on earlier comparative runs: - **V11 shows 1.8-3.4% faster** read performance for smaller datasets - **More consistent performance** with lower standard deviations - **Bulk reads perform equivalently** between versions #### Write Performance - **Sequential writes**: Comparable performance - **Bulk writes**: V11 shows **significant advantages** with new bulk API - **Object serialization**: **SystemTextJson in V11 outperforms** legacy serialization #### Memory Usage - **Generally equivalent or better** memory efficiency in V11 - **More predictable allocation patterns** - **Garbage collection performance improved** ## Serializer Performance Comparison ### System.Text.Json (V11 Default) - **~260ms for 100 complex objects** (serialization + storage + retrieval) - **2,029.27 KB memory allocation** - **Best choice for new applications** ### Cross-Serializer Compatibility Benefits V11 can read data written by different serializers: ```csharp // Write with one serializer CacheDatabase.Serializer = new NewtonsoftBsonSerializer(); await cache.InsertObject("key", data); // Read with another serializer CacheDatabase.Serializer = new SystemJsonSerializer(); var retrieved = await cache.GetObject("key"); // Still works! ``` ## Cache Type Performance Analysis All cache types show **remarkably consistent performance** in V11: | Cache Type | 100 Items | 1000 Items | Use Case | |------------|-----------|------------|----------| | **UserAccount** | 253.847 ms | 2,603.138 ms | **User settings, preferences** | | **LocalMachine** | 257.036 ms | 2,642.941 ms | **Cached API data, temporary files** | | **Secure** | 255.278 ms | 2,620.867 ms | **Credentials, sensitive data** | | **InMemory** | 18.796 ms | 122.826 ms | **Session data, frequently accessed** | **Key Insight**: Persistent cache types perform within **2% of each other**, showing excellent architecture consistency. ## Advanced Operation Performance ### GetOrFetch Pattern (Cache-Miss Scenario) - **45.034 ms for 1000 operations** - **Ideal for API data caching with fallback** - **Efficient handling of cache misses** ### Mixed Operations (Real-World Simulation) - **3,552.625 ms for 1000 complex operations** - Includes: Insert ? Read ? Update ? Verify cycle - **Demonstrates excellent real-world performance** ### Expiration Handling - **2,604.595 ms for 1000 items with expiration** - **Minimal overhead for time-based invalidation** - **Essential for API caching scenarios** ## Migration Performance Impact ### From V10 to V11 - **< 5% performance difference** for most operations - **Significant improvements in consistency** - **Better error handling and recovery** ### Breaking Changes 1. **Initialization pattern** requires code changes 2. **Must explicitly choose serializer** 3. **Package structure** requires dependency updates ### Migration Benefits 1. **Future-proof architecture** 2. **Better performance monitoring** 3. **Enhanced debugging capabilities** 4. **Serializer flexibility** ## Best Practices for Optimal Performance ### 1. Choose the Right Serializer ```csharp // For new applications (fastest) CacheDatabase.Serializer = new SystemJsonSerializer(); // For V10 compatibility (most compatible) CacheDatabase.Serializer = new NewtonsoftBsonSerializer(); ``` ### 2. Use Bulk Operations When Possible ```csharp // Instead of multiple individual inserts await cache.InsertObjects(largeDataSet); // Much faster! ``` ### 3. Leverage Cache Type Appropriately ```csharp // Fast temporary data await CacheDatabase.InMemory.InsertObject("session", data); // Persistent user data await CacheDatabase.UserAccount.InsertObject("settings", userSettings); ``` ### 4. Optimize with GetOrFetch Pattern ```csharp var data = await cache.GetOrFetchObject("api_data", () => httpClient.GetFromJsonAsync(url)); ``` ## Recommendations ### Choose V11 for New Projects - **Similar or better performance** - **Modern, maintainable architecture** - **Future-proof design** - **Enhanced developer experience** ### Migrate from V10 When - You need **multiple serializer support** - You want **better error handling** - You require **cross-serializer compatibility** - Performance is **not the primary concern** (impact minimal) ### Consider Carefully for - **Large sequential read workloads** (8.6% slower in some cases) - **Legacy data requiring specific serialization** - **Applications with extremely tight performance budgets** ### Performance-Critical Applications - Use **System.Text.Json** serializer - Leverage **bulk operations** wherever possible - Consider **InMemory cache** for frequently accessed data - Implement proper **expiration strategies** ## Conclusion Akavache V11.0 successfully delivers on its architectural improvements while maintaining **excellent performance characteristics**. The comprehensive benchmarks show: - **Performance** : Generally equal or better than V10 - **Consistency** : Much more predictable performance patterns - **Flexibility** : Multiple serializer options for optimization - **Architecture** : Modern, maintainable, and extensible design **Bottom Line**: V11 is a compelling upgrade that provides architectural benefits without significant performance regression. The slight trade-offs in specific scenarios are more than offset by the improved developer experience, better error handling, and future-proof design. --- *Performance data collected using BenchmarkDotNet v0.15.2 on .NET 9.0. Results represent typical performance and may vary based on hardware configuration, data characteristics, and usage patterns.*