# Performance

## Overview

The Performance feature is primarily managed by the `StrokeHistory` property, which sets the maximum number of stored signature strokes to balance memory consumption with the depth of the undo functionality. Additionally, internal optimizations—such as double buffering and bitmap caching—ensure smooth rendering of the signature pad even under heavy usage.

***

### Detailed Documentation

#### Key Points

<table><thead><tr><th width="241">Aspect</th><th>Details</th></tr></thead><tbody><tr><td>Stroke History Limit</td><td><code>StrokeHistory</code> – Determines the maximum number of signature strokes stored, balancing undo capabilities and memory usage.</td></tr><tr><td>Memory Management</td><td>Internally, the control employs bitmap caching and double buffering to reduce flickering and improve redraw performance.</td></tr><tr><td>Responsiveness</td><td>Efficient caching mechanisms help maintain responsiveness even when multiple strokes have been drawn.</td></tr></tbody></table>

#### Best Practices

| Practice                               | Recommendation                                                                                                                                   |
| -------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------ |
| Set an Appropriate StrokeHistory Value | Choose a value for `StrokeHistory` that provides sufficient undo depth while avoiding excessive memory consumption.                              |
| Monitor Application Memory Usage       | Test the signature pad under realistic usage scenarios to ensure that the chosen stroke history limit maintains overall application performance. |
| Leverage Internal Caching Mechanisms   | Allow the control’s built-in double buffering and caching to optimize rendering; avoid custom overrides that might bypass these optimizations.   |

#### Common Pitfalls

| Pitfall                              | Mitigation                                                                                                                                                       |
| ------------------------------------ | ---------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Excessive Memory Usage               | Setting an excessively high `StrokeHistory` value may lead to increased memory consumption; fine-tune the value based on expected signature complexity.          |
| Reduced Undo Capability              | Conversely, setting a very low `StrokeHistory` value might limit the user's ability to undo strokes; find a balanced value that meets your application's needs.  |
| Neglecting Internal Caching Benefits | Overriding or disabling the control’s default caching mechanisms can result in flickering or sluggish performance; use built-in optimizations wherever possible. |

#### Usage Scenarios

<table><thead><tr><th width="351">Scenario</th><th>Description</th></tr></thead><tbody><tr><td>Applications with High Signature Volume</td><td>In environments where users input numerous strokes, a carefully chosen <code>StrokeHistory</code> value prevents memory overuse while supporting multiple undo operations.</td></tr><tr><td>Performance-Critical Interfaces</td><td>Applications with strict performance requirements can benefit from the control's internal caching and double buffering to ensure smooth rendering.</td></tr><tr><td>Undo-Intensive Workflows</td><td>Use the <code>StrokeHistory</code> property to provide a deeper undo history for users who need to frequently correct their input without compromising performance.</td></tr></tbody></table>

#### Real Life Usage Scenarios

<table><thead><tr><th width="242">Scenario</th><th>Description</th></tr></thead><tbody><tr><td>Financial Forms</td><td>Banking or financial applications where signatures must be captured quickly and accurately benefit from controlled stroke history and optimized rendering.</td></tr><tr><td>Legal Document Signing</td><td>In legal settings, users may need to review and correct their signatures extensively; an optimal <code>StrokeHistory</code> ensures sufficient undo capability without memory issues.</td></tr><tr><td>Educational Applications</td><td>Software used for teaching handwriting or signature formation can leverage performance optimizations to allow extended practice sessions without lag.</td></tr></tbody></table>

#### Code Examples

**Example 1: Configuring Stroke History**

```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

public class PerformanceForm : Form
{
    private SiticoneSignaturePad signaturePad;

    public PerformanceForm()
    {
        // Initialize the signature pad control
        signaturePad = new SiticoneSignaturePad
        {
            Location = new Point(10, 10),
            Size = new Size(400, 200),
            
            // Set maximum number of stored strokes to balance memory and undo capabilities
            StrokeHistory = 50
        };

        // Add the signature pad to the form
        Controls.Add(signaturePad);
    }
    
    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new PerformanceForm());
    }
}
```

**Example 2: Adjusting Performance for High-Usage Scenarios**

```csharp
using System;
using System.Drawing;
using System.Windows.Forms;
using SiticoneNetFrameworkUI;

public class HighUsagePerformanceForm : Form
{
    private SiticoneSignaturePad signaturePad;
    private Button increaseHistoryButton;

    public HighUsagePerformanceForm()
    {
        // Initialize the signature pad control with default performance settings
        signaturePad = new SiticoneSignaturePad
        {
            Location = new Point(10, 10),
            Size = new Size(400, 200),
            StrokeHistory = 30 // Initial value suitable for most applications
        };

        // Button to increase the stroke history limit dynamically
        increaseHistoryButton = new Button
        {
            Text = "Increase Stroke History",
            Location = new Point(10, 220),
            Size = new Size(180, 30)
        };
        increaseHistoryButton.Click += IncreaseHistoryButton_Click;

        // Add controls to the form
        Controls.Add(signaturePad);
        Controls.Add(increaseHistoryButton);
    }

    private void IncreaseHistoryButton_Click(object sender, EventArgs e)
    {
        // Increase the stroke history limit for more undo capacity
        signaturePad.StrokeHistory += 10;
        MessageBox.Show($"Stroke history increased to {signaturePad.StrokeHistory}.", "Performance Update", MessageBoxButtons.OK, MessageBoxIcon.Information);
    }
    
    [STAThread]
    public static void Main()
    {
        Application.EnableVisualStyles();
        Application.Run(new HighUsagePerformanceForm());
    }
}
```

#### Troubleshooting Tips

<table><thead><tr><th width="279">Tip</th><th>Explanation</th></tr></thead><tbody><tr><td>Monitor Memory Usage</td><td>Use diagnostic tools to monitor memory usage when adjusting <code>StrokeHistory</code>, ensuring that increased undo depth does not degrade performance.</td></tr><tr><td>Test Under Realistic Conditions</td><td>Evaluate the performance of the signature pad with a typical workload to determine the optimal <code>StrokeHistory</code> value for your application.</td></tr><tr><td>Rely on Built-In Optimizations</td><td>Avoid custom rendering logic that may bypass the control’s caching and double buffering, as these are critical for maintaining performance.</td></tr><tr><td>Profile Rendering Speed</td><td>If rendering seems sluggish, profile the application to check whether the caching mechanisms are effectively reducing redraw times.</td></tr></tbody></table>

#### Review

<table><thead><tr><th width="140">Aspect</th><th>Review Comments</th></tr></thead><tbody><tr><td>Integration</td><td>The performance-related properties are straightforward to configure, making it easy to balance memory usage and undo capabilities.</td></tr><tr><td>Efficiency</td><td>Internal caching and double buffering contribute to smooth performance even when the control handles multiple strokes.</td></tr><tr><td>Adaptability</td><td>The <code>StrokeHistory</code> property provides flexibility to accommodate various application scenarios, from low-usage to high-usage environments.</td></tr></tbody></table>

#### Summary

The Performance feature in the SiticoneSignaturePad control focuses on managing the maximum number of stored signature strokes through the `StrokeHistory` property while leveraging caching and double buffering to ensure smooth rendering. This feature allows developers to optimize the control's responsiveness and memory usage based on the expected signature complexity and application requirements.
