-
Notifications
You must be signed in to change notification settings - Fork 10
Design and performance improvement: introduces internal object pooling, refactors rendering and dialog infrastructure, and tightens API visibility #310
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- 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.
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
IPooledStringBuilderLeaseFactory,PooledStringBuilderLease, and related pooling infrastructure; updates DI registration inServiceConfiguration.cs.MermaidRendererto use pooled StringBuilder for escaping, improves thread safety, and makes key methods internal.DiagramViewModelto serialize render requests and ensure only the latest render is processed.ExportService,FileService,ExportDialogViewModel) internal for encapsulation.DialogBasefor robust, thread-safe dialog handling and refactors dialog classes to inherit from it.