Skip to content

Conversation

@udlose
Copy link
Owner

@udlose udlose commented Jan 1, 2026

PR Classification

Design and performance improvement: introduces internal object pooling, refactors rendering and dialog infrastructure, and tightens API visibility.

PR Summary

This pull request adds an internal StringBuilder object pooling system, refactors Mermaid rendering and dialog handling for better performance and thread safety, and restricts service/model visibility to internal.

  • Adds IPooledStringBuilderLeaseFactory, PooledStringBuilderLease, and related pooling infrastructure; updates DI registration in ServiceConfiguration.cs.
  • Refactors MermaidRenderer to use pooled StringBuilder for escaping, improves thread safety, and makes key methods internal.
  • Updates DiagramViewModel to serialize render requests and ensure only the latest render is processed.
  • Makes service, model, and dialog classes (e.g., ExportService, FileService, ExportDialogViewModel) internal for encapsulation.
  • Introduces DialogBase for robust, thread-safe dialog handling and refactors dialog classes to inherit from it.

- Add CharacterEllipsis trimming to StatusTextBlock for better handling of long status messages.
- Remove DockPanel.Dock="Top" from main content Grid and clarify layout intent with a comment to ensure proper space filling.
…ts - effectively "ordering them"

Add SemaphoreSlim to serialize Mermaid diagram rendering in DiagramViewModel and implement a last-write-wins strategy using an atomic render sequence. Only the latest render request is processed, improving thread safety and responsiveness during rapid updates.
… cancellation logic

- Add ObjectPoolRegistrations for DI-based pooling of StringBuilder and HashSet<string>
- Introduce PooledStringBuilderLease for safe pooled usage
- Reference Microsoft.Extensions.ObjectPool.DependencyInjection
- Refactor MermaidRenderer cancellation with helper method
- Make AssetIntegrityService.GetStoredHashForAsset and SecurityService.IsFileNameSecure static
- Enhance logging, code style, and documentation
- Update code inspection settings for stricter quality
…riable captures for lambdas.

Refactored RenderAsync to return Task<string?> and always provide a result, splitting logic into static local functions for UI thread safety and reduced variable capture. Added RenderOnUIThreadAsync and ClearOnUIThreadAsync helpers. Updated UnregisterExportProgressCallbackAsync to delegate to a new private async method. Improved XML documentation for all affected methods.
Refactor object pooling to use a new IPooledStringBuilderLeaseFactory interface and its implementation, PooledStringBuilderLeaseFactory, for efficient and safe StringBuilder reuse via a lease pattern. Replace direct ObjectPool<StringBuilder> registration with the new factory, remove obsolete pooling methods, and update namespaces accordingly. Add MIT license headers and improve documentation for maintainability.
Refactor request path constants to be class-level const/static fields instead of constructor-initialized fields. Extract WebView navigation logic into a new NavigateToServerCoreAsync helper method, improving code clarity and maintainability. Centralize navigation timeout handling and simplify the constructor.
Expanded XML docs for Rent() to clarify usage and caller responsibilities. Added [MustDisposeResource] and [MustUseReturnValue] attributes to enforce correct usage. Included JetBrains.Annotations using directive.
Refactor StringBuilder pooling to use multiple capacity-based pools
(256, 1024, 4096, 16384 chars) via new PooledStringBuilderBucketedLeaseFactory.
Extend IPooledStringBuilderLeaseFactory with Rent(int minimumCapacity)
to allow callers to request builders of a specific minimum size.
Remove the old single-pool factory. This change reduces memory waste
from "large builder contamination" and improves performance for
scenarios with varying string sizes. Update documentation accordingly.
Introduce ServiceBase for pooled StringBuilder management and refactor MermaidRenderer to inherit from it. EscapeSource now uses a pooled StringBuilder for improved memory efficiency. MermaidRenderer is now internal and its constructor requires an IPooledStringBuilderLeaseFactory. Includes minor code cleanups and improved parameter passing.

Refactor MermaidRenderer to use pooled StringBuilder leases

Introduce ServiceBase for pooled StringBuilder management and refactor MermaidRenderer to inherit from it. EscapeSource now uses pooled StringBuilder leases for improved memory efficiency. MermaidRenderer is now internal and requires an IPooledStringBuilderLeaseFactory. Added ServiceBase.cs to encapsulate pooled StringBuilder logic and enforce proper usage.
Replaced separate Contains calls with SearchValues<char> and ContainsAny for more efficient detection of escape characters in Mermaid source strings. Introduced a static field to hold escape characters and simplified conditional logic, improving performance and readability.
Changed ExportService, AssetIntegrityService, AssetService, SecurityService, and ExportDialogViewModel from public to internal sealed classes. Updated related methods and properties to internal to improve encapsulation and limit API surface. No functional changes; only access modifiers were updated.
…d - oops!

ExportSvgAsync now takes both file path and SvgOptions,
enabling more customizable SVG exports via the export dialog.
…ut', refactor dialogs to use DialogBase for common behavior

Introduce DialogBase to encapsulate shared dialog logic, such as non-resizability and safe, thread-aware closing methods. Update ConfirmationDialog and MessageDialog to inherit from DialogBase and use CloseDialog methods instead of direct Close calls. Change dialog classes to internal and remove redundant CanResize assignments.
ServiceBase no longer depends on IPooledStringBuilderLeaseFactory and removes all pooled StringBuilder lease methods. MermaidRenderer now manages its own lease factory reference and usage. This decouples pooled resource management from the base class, simplifying ServiceBase and clarifying responsibilities. Also adds ApplicationName constant and a commented config path helper.
@udlose udlose self-assigned this Jan 1, 2026
@udlose udlose added this to the 2.0.0 milestone Jan 1, 2026
@udlose udlose added .NET Pull requests that update .NET code performance Optimization of speed or memory allocation user interface Covers changes, bug fixes and improvements to the UI backend Covers changes, bug fixes, and improvements to the backend implementation. refactoring Changes related to refactoring existing functionality threading Stability issues from race conditions, reentrancy, cross-thread marshaling errors, etc. labels Jan 1, 2026
@udlose udlose merged commit 4c4ccb0 into main Jan 1, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend Covers changes, bug fixes, and improvements to the backend implementation. .NET Pull requests that update .NET code performance Optimization of speed or memory allocation refactoring Changes related to refactoring existing functionality threading Stability issues from race conditions, reentrancy, cross-thread marshaling errors, etc. user interface Covers changes, bug fixes and improvements to the UI

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants