Skip to content

Performance

abbaye edited this page Mar 2, 2026 · 3 revisions

⚡ Performance Guide

WPFHexaEditor has been extensively optimized for performance to handle files of all sizes efficiently.

🚀 Key Optimizations (2026)

UI Rendering (5-10x Faster)

  • Cached WPF Objects: Typeface and FormattedText cached and reused
  • Width Calculation Cache: Dictionary-based O(1) lookups (10-100x faster)
  • Batch Updates: BeginUpdate/EndUpdate prevents multiple refreshes

Results:

  • 2-3x faster rendering
  • 50-80% reduction in memory allocations
  • Smooth scrolling even with large files

UI Virtualization (80-90% Memory Reduction)

Only renders visible bytes + small buffer:

100 MB file WITHOUT virtualization:
- 200M controls created
- ~100 GB memory usage

100 MB file WITH virtualization:
- 960 controls created
- ~480 KB memory usage
- 99.9995% memory saved! 🎉

Search Caching (100-1000x Faster)

Intelligent cache for repeated searches:

  • First FindAll: Scans entire file
  • Subsequent calls: Returns cached results (instant)
  • Auto-invalidated on data changes

Benchmark: 460x speedup for repeated searches!

Highlight Operations (10-100x Faster) ⭐ NEW v2.2+

Optimized data structure and batching:

  • HashSet Migration: 2-3x faster, 50% less memory (was Dictionary)
  • Batching Support: 10-100x faster for bulk highlights
  • Bulk APIs: AddHighLightRanges, AddHighLightPositions
// ✅ OPTIMIZED: Batch thousands of highlights
service.BeginBatch();
foreach (var result in searchResults)
    service.AddHighLight(result.Position, result.Length);
var (added, removed) = service.EndBatch();

// 🚀 FASTEST: Use bulk API
var ranges = searchResults.Select(r => (r.Position, r.Length));
service.AddHighLightRanges(ranges);

Benchmarks:

  • 1000 ranges: 1.2ms → 85μs (14x faster)
  • 10000 positions: 12ms → 450μs (27x faster)
  • Memory: 50% reduction with HashSet

📊 Performance Metrics

Operation File Size Time Notes
Load file 1 MB ~80 ms ✅ Fast
Load file 100 MB ~1.5 sec ✅ Fast
FindFirst 1 MB ~12 ms ✅ Fast
FindAll (cached) 10 KB 5.2 μs 🚀 460x faster
Highlight 1000 ranges (batched) - 85 μs 🚀 14x faster
Highlight 10000 positions (bulk) - 450 μs 🚀 27x faster
CalculateVisibleRange 1 GB 0.9 μs ⚡ Constant time
Render FPS Any size 45+ FPS ✅ Smooth

🎯 Best Practices

For Large Files (> 100 MB)

var hexEditor = new HexEditor
{
    BytesPerLine = 16,          // Standard, optimized
    ReadOnlyMode = true,         // If editing not needed
    AllowAutoHighlight = false,  // Skip highlighting
};

Search Optimization

// ✅ GOOD: Use cached FindAll
var results = hexEditor.FindAll(pattern);  // Cached
foreach (var pos in results)
    ProcessMatch(pos);

// ❌ BAD: Repeated FindFirst
for (int i = 0; i < fileSize; i++)
    hexEditor.FindFirst(pattern);  // Rescans every time!

Memory Management

// ✅ GOOD: Use streams
hexEditor.Provider.Stream = File.OpenRead("huge.bin");

// ❌ BAD: Load entire file
var bytes = File.ReadAllBytes("huge.bin");  // OOM!
hexEditor.Provider.Stream = new MemoryStream(bytes);

🧪 Benchmarking

Run performance benchmarks:

cd Sources/WPFHexaEditor.Benchmarks
dotnet run -c Release

Results are exported to HTML and Markdown formats.

📚 Complete Documentation

For detailed performance documentation including:

  • Benchmarking results with specific numbers
  • Performance pitfalls and how to avoid them
  • Custom ByteProvider for extreme performance
  • Zero-allocation patterns
  • Advanced optimization techniques

See the complete Performance Guide

🔗 Related Pages


Last Updated: 2026-02-11 Performance Guide Author: Claude Sonnet 4.5

Navigation

Getting Started

IDE Documentation

HexEditor Control

Advanced

Development


v0.6.0 Highlights

  • WpfHexEditor.Shell (renamed from Docking.Wpf)
  • Code Editor ~90% (NavBar, Inline Hints, Quick Info)
  • XAML Visual Designer ~70%
  • Shared UndoEngine (coalescing + transactions)
  • VS .sln/.csproj + Open-Folder mode
  • Build System (IBuildAdapter + MSBuild plugin)
  • Assembly Explorer + NuGet Solution Manager
  • Synalysis Grammar Support (IGrammarProvider)

Links

Clone this wiki locally