refactor: optimize event args handling for performance improvements

This commit is contained in:
Miha Kralj
2025-12-28 17:21:53 -08:00
parent a64cc1c224
commit ad6eebf812
47 changed files with 59 additions and 51 deletions
+2 -3
View File
@@ -6,9 +6,8 @@ using System.Runtime.InteropServices;
namespace QuanTAlib;
/// <summary>
/// A high-performance OHLCV time series implementation using Structure of Arrays (SoA) layout.
/// Stores Time, Open, High, Low, Close, Volume in separate contiguous arrays for SIMD efficiency.
/// Exposes TSeries views for each component that share the underlying Time array.
/// Performance-focused event args for TBar updates.
/// Implemented as struct to avoid heap allocations in high-frequency event dispatch.
/// </summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct TBarEventArgs
+12 -2
View File
@@ -1,14 +1,24 @@
using System;
using System.Runtime.InteropServices;
namespace QuanTAlib;
public sealed class TValueEventArgs : EventArgs
/// <summary>
/// Performance-focused event args for TValue updates.
/// Implemented as struct to avoid heap allocations in high-frequency event dispatch.
/// </summary>
[StructLayout(LayoutKind.Auto)]
public readonly struct TValueEventArgs
{
public TValue Value { get; init; }
public bool IsNew { get; init; }
}
public delegate void TValuePublishedHandler(object? sender, TValueEventArgs args);
// Performance-focused event args struct; not derived from EventArgs by design.
// We intentionally deviate from the standard EventArgs pattern here for perf.
#pragma warning disable MA0046 // The second parameter must be of type 'System.EventArgs' or a derived type
public delegate void TValuePublishedHandler(object? sender, in TValueEventArgs args);
#pragma warning restore MA0046
/// <summary>
/// Interface for objects that publish TValue updates.
+1 -2
View File
@@ -109,8 +109,7 @@ public class TSeries : IReadOnlyList<TValue>, ITValuePublisher
_v[lastIdx] = value.Value;
}
var args = new TValueEventArgs { Value = value, IsNew = isNew };
Pub?.Invoke(this, args);
Pub?.Invoke(this, new TValueEventArgs { Value = value, IsNew = isNew });
}
// Overload for backward compatibility (assumes isNew=true)