Improved caching
This commit is contained in:
Родитель
7980befb77
Коммит
88e58500a8
|
@ -1,6 +1,7 @@
|
|||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using BenchmarkDotNet.Attributes;
|
||||
using BenchmarkDotNet.Configs;
|
||||
using BenchmarkDotNet.Engines;
|
||||
using BenchmarkDotNet.Running;
|
||||
using Microsoft.VisualStudio.TestPlatform.TestHost;
|
||||
|
@ -20,7 +21,11 @@ namespace QuestPDF.ReportSample
|
|||
[Test]
|
||||
public void Run()
|
||||
{
|
||||
BenchmarkRunner.Run<PerformanceTests>();
|
||||
var configuration = ManualConfig
|
||||
.Create(DefaultConfig.Instance)
|
||||
.WithOptions(ConfigOptions.DisableOptimizationsValidator);
|
||||
|
||||
BenchmarkRunner.Run<PerformanceTests>(configuration);
|
||||
}
|
||||
|
||||
[IterationSetup]
|
||||
|
|
|
@ -11,7 +11,7 @@
|
|||
<PackageReference Include="BenchmarkDotNet" Version="0.13.1" />
|
||||
<PackageReference Include="nunit" Version="3.13.2" />
|
||||
<PackageReference Include="NUnit3TestAdapter" Version="4.0.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.5.0" />
|
||||
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.11.0" />
|
||||
<PackageReference Include="SkiaSharp" Version="2.80.3" />
|
||||
</ItemGroup>
|
||||
|
||||
|
|
|
@ -112,20 +112,21 @@ namespace QuestPDF.Drawing
|
|||
|
||||
private static void ApplyCaching(Container content)
|
||||
{
|
||||
content.HandleVisitor(x => x.CreateProxy(y => new CacheProxy
|
||||
content.HandleVisitor(x =>
|
||||
{
|
||||
Child = y
|
||||
}));
|
||||
if (x is ICacheable)
|
||||
x.CreateProxy(y => new CacheProxy(y));
|
||||
});
|
||||
}
|
||||
|
||||
private static DebuggingState ApplyDebugging(Container content)
|
||||
{
|
||||
var debuggingState = new DebuggingState();
|
||||
|
||||
content.HandleVisitor(x => x.CreateProxy(y => new DebuggingProxy(debuggingState)
|
||||
content.HandleVisitor(x =>
|
||||
{
|
||||
Child = y
|
||||
}));
|
||||
x.CreateProxy(y => new DebuggingProxy(debuggingState, x));
|
||||
});
|
||||
|
||||
return debuggingState;
|
||||
}
|
||||
|
|
|
@ -8,6 +8,11 @@ namespace QuestPDF.Drawing.Proxy
|
|||
public Size? AvailableSpace { get; set; }
|
||||
public SpacePlan? MeasurementResult { get; set; }
|
||||
|
||||
public CacheProxy(Element child)
|
||||
{
|
||||
Child = child;
|
||||
}
|
||||
|
||||
internal override SpacePlan Measure(Size availableSpace)
|
||||
{
|
||||
if (MeasurementResult != null &&
|
||||
|
|
|
@ -6,9 +6,10 @@ namespace QuestPDF.Drawing.Proxy
|
|||
{
|
||||
private DebuggingState DebuggingState { get; }
|
||||
|
||||
public DebuggingProxy(DebuggingState debuggingState)
|
||||
public DebuggingProxy(DebuggingState debuggingState, Element child)
|
||||
{
|
||||
DebuggingState = debuggingState;
|
||||
Child = child;
|
||||
}
|
||||
|
||||
internal override SpacePlan Measure(Size availableSpace)
|
||||
|
|
|
@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class AspectRatio : ContainerElement
|
||||
internal class AspectRatio : ContainerElement, ICacheable
|
||||
{
|
||||
public float Ratio { get; set; } = 1;
|
||||
public AspectRatioOption Option { get; set; } = AspectRatioOption.FitWidth;
|
||||
|
|
|
@ -6,7 +6,7 @@ namespace QuestPDF.Elements
|
|||
{
|
||||
public delegate void DrawOnCanvas(SKCanvas canvas, Size availableSpace);
|
||||
|
||||
internal class Canvas : Element
|
||||
internal class Canvas : Element, ICacheable
|
||||
{
|
||||
public DrawOnCanvas Handler { get; set; }
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Constrained : ContainerElement
|
||||
internal class Constrained : ContainerElement, ICacheable
|
||||
{
|
||||
public float? MinWidth { get; set; }
|
||||
public float? MaxWidth { get; set; }
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace QuestPDF.Elements
|
|||
Append
|
||||
}
|
||||
|
||||
internal class BinaryDecoration : Element
|
||||
internal class BinaryDecoration : Element, ICacheable
|
||||
{
|
||||
public Element DecorationElement { get; set; } = Empty.Instance;
|
||||
public Element ContentElement { get; set; } = Empty.Instance;
|
||||
|
|
|
@ -3,7 +3,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class EnsureSpace : ContainerElement
|
||||
internal class EnsureSpace : ContainerElement, ICacheable
|
||||
{
|
||||
public const float DefaultMinHeight = 150;
|
||||
public float MinHeight { get; set; } = DefaultMinHeight;
|
||||
|
|
|
@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Extend : ContainerElement
|
||||
internal class Extend : ContainerElement, ICacheable
|
||||
{
|
||||
public bool ExtendVertical { get; set; }
|
||||
public bool ExtendHorizontal { get; set; }
|
||||
|
|
|
@ -4,7 +4,7 @@ using SkiaSharp;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Image : Element
|
||||
internal class Image : Element, ICacheable
|
||||
{
|
||||
public SKImage? InternalImage { get; set; }
|
||||
|
||||
|
|
|
@ -11,7 +11,7 @@ namespace QuestPDF.Elements
|
|||
public bool IsPrimary { get; set; }
|
||||
}
|
||||
|
||||
internal class Layers : Element
|
||||
internal class Layers : Element, ICacheable
|
||||
{
|
||||
public List<Layer> Children { get; set; } = new List<Layer>();
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Padding : ContainerElement
|
||||
internal class Padding : ContainerElement, ICacheable
|
||||
{
|
||||
public float Top { get; set; }
|
||||
public float Right { get; set; }
|
||||
|
|
|
@ -34,7 +34,7 @@ namespace QuestPDF.Elements
|
|||
}
|
||||
}
|
||||
|
||||
internal class BinaryRow : Element
|
||||
internal class BinaryRow : Element, ICacheable
|
||||
{
|
||||
internal Element Left { get; set; }
|
||||
internal Element Right { get; set; }
|
||||
|
|
|
@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Scale : ContainerElement
|
||||
internal class Scale : ContainerElement, ICacheable
|
||||
{
|
||||
public float ScaleX { get; set; } = 1;
|
||||
public float ScaleY { get; set; } = 1;
|
||||
|
|
|
@ -3,7 +3,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class ShowEntire : ContainerElement
|
||||
internal class ShowEntire : ContainerElement, ICacheable
|
||||
{
|
||||
internal override SpacePlan Measure(Size availableSpace)
|
||||
{
|
||||
|
|
|
@ -3,7 +3,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class ShowOnce : ContainerElement, IStateResettable
|
||||
internal class ShowOnce : ContainerElement, IStateResettable, ICacheable
|
||||
{
|
||||
private bool IsRendered { get; set; }
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class SimpleRotate : ContainerElement
|
||||
internal class SimpleRotate : ContainerElement, ICacheable
|
||||
{
|
||||
public int TurnCount { get; set; }
|
||||
public int NormalizedTurnCount => (TurnCount % 4 + 4) % 4;
|
||||
|
|
|
@ -9,7 +9,7 @@ using IContainer = QuestPDF.Infrastructure.IContainer;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class BinaryStack : Element, IStateResettable
|
||||
internal class BinaryStack : Element, IStateResettable, ICacheable
|
||||
{
|
||||
internal Element First { get; set; } = Empty.Instance;
|
||||
internal Element Second { get; set; } = Empty.Instance;
|
||||
|
|
|
@ -3,7 +3,7 @@ using QuestPDF.Infrastructure;
|
|||
|
||||
namespace QuestPDF.Elements
|
||||
{
|
||||
internal class Unconstrained : ContainerElement
|
||||
internal class Unconstrained : ContainerElement, ICacheable
|
||||
{
|
||||
internal override SpacePlan Measure(Size availableSpace)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
namespace QuestPDF.Infrastructure
|
||||
{
|
||||
public interface ICacheable
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Загрузка…
Ссылка в новой задаче