Skip to content

Commit

Permalink
refactor: reduce memory footprint of statistics functionality (#602)
Browse files Browse the repository at this point in the history
Currently all calls during the initialization result in an initialized `ConcurrentDictionary` for each path. This PR changes the behaviour, that the entries of `PathStatistics` are only added, during a normal statistic registration.
  • Loading branch information
vbreuss authored May 15, 2024
1 parent fc4df09 commit 0c2b777
Show file tree
Hide file tree
Showing 17 changed files with 1,447 additions and 945 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using System.Diagnostics.CodeAnalysis;
using System.IO;
using Testably.Abstractions.Testing.Helpers;
using Testably.Abstractions.Testing.Statistics;

namespace Testably.Abstractions.Testing.FileSystem;

Expand All @@ -24,8 +23,9 @@ public IFileSystem FileSystem
/// <inheritdoc cref="IDirectoryInfoFactory.New(string)" />
public IDirectoryInfo New(string path)
{
using IDisposable registration = RegisterMethod(nameof(New),
path);
using IDisposable registration = _fileSystem.StatisticsRegistration
.DirectoryInfo.RegisterMethod(nameof(New),
path);

return DirectoryInfoMock.New(
_fileSystem.Storage.GetLocation(path
Expand All @@ -37,8 +37,9 @@ public IDirectoryInfo New(string path)
[return: NotNullIfNotNull("directoryInfo")]
public IDirectoryInfo? Wrap(DirectoryInfo? directoryInfo)
{
using IDisposable registration = RegisterMethod(nameof(Wrap),
directoryInfo);
using IDisposable registration = _fileSystem.StatisticsRegistration
.DirectoryInfo.RegisterMethod(nameof(Wrap),
directoryInfo);

if (_fileSystem.SimulationMode != SimulationMode.Native)
{
Expand All @@ -54,8 +55,4 @@ public IDirectoryInfo New(string path)
}

#endregion

private IDisposable RegisterMethod<T1>(string name, T1 parameter1)
=> _fileSystem.StatisticsRegistration.DirectoryInfo.RegisterMethod(name,
ParameterDescription.FromParameter(parameter1));
}
Loading

0 comments on commit 0c2b777

Please sign in to comment.