-
-
Notifications
You must be signed in to change notification settings - Fork 141
Performance
abbaye edited this page Mar 2, 2026
·
3 revisions
WPFHexaEditor has been extensively optimized for performance to handle files of all sizes efficiently.
- 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
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! 🎉
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!
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
| 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 |
var hexEditor = new HexEditor
{
BytesPerLine = 16, // Standard, optimized
ReadOnlyMode = true, // If editing not needed
AllowAutoHighlight = false, // Skip highlighting
};// ✅ 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!// ✅ 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);Run performance benchmarks:
cd Sources/WPFHexaEditor.Benchmarks
dotnet run -c ReleaseResults are exported to HTML and Markdown formats.
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
- Architecture - Service-based design for performance
- Getting Started - Quick start guide
- API Reference - Complete API documentation
Last Updated: 2026-02-11 Performance Guide Author: Claude Sonnet 4.5
✨ Wpf HexEditor user control, by Derek Tremblay (derektremblay666@gmail.com) coded for your fun! 😊🤟
- API Reference
- Performance
- Services
- Core Components
- ByteProvider
- Rendering Engine
- Search Architecture
- 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)