Back to writing
Blog Post

Porting SqlQueryStress from WPF to Avalonia

avaloniasqlcross-platformwpfdotnet
Porting SqlQueryStress from WPF to Avalonia

SqlQueryStress is a SQL benchmarking tool that lets you stress-test T-SQL queries with configurable concurrency, iterations, and parameter substitution.

The porting process was a joint effort between myself and Semilore as part of the Avalonia Port Challenge.

We migrated ErikEJ's Windows-only WPF SqlQueryStress to a cross-platform Avalonia 12 application targeting .NET 10, preserving all original functionality while rebuilding the entire presentation layer.

We added macOS and Linux support, introduced a fully testable service-oriented architecture, and added automatic system theme syncing. Building the UI was quite seamless with Avalonia's layout system, and we particularly liked how easy it was to add automatic light/dark mode.

We preserved the original application's benchmark export formats (plain text, CSV, and clipboard) and maintained the same format for saving/loading settings such that users could use the same settings file between the two applications.

The migration happened in a couple of distinct phases:

  • Building the Views for each of the windows in the original app
  • Creating the respective ViewModels for some of the Views. The ViewModels were just skeletons at this point and was used to map out the data that will be passed to the Views
  • Extracting the business logic from the original app and creating services out of it along with some unit tests
  • Hooking up those services into the ViewModels and verifying that the features work
  • Adding more tests to the test suite
  • Deploying the migrated application

SqlQueryStress running on MacOS

What Translated Cleanly

The original Microsoft.Data.SqlClient execution model required no abstraction layer. We referenced the same NuGet package directly, and the existing pattern for capturing telemetry data during benchmarks worked identically across platforms.

Saving/Loading of the application's settings via JSON and the query parameter substitution logic carried over smoothly once decoupled from UI controls.

We replaced WPF's AvalonEdit text editor with AvaloniaEdit allowing us to preserve full T-SQL syntax highlighting with native Light and Dark mode reactivity.

What Needed Rethinking

The original application had business logic embedded in WPF code-behind files with limited testability. We introduced new service interfaces with dedicated implementations, new view models, dependency injection, and a full xUnit test suite covering the load engine, parameter server, query worker, and export formatting all without requiring a live SQL Server instance.

During stress testing with 20+ concurrent threads running sub-millisecond queries (10,000+ iterations), sending telemetry updates to the UI thread on every single query completion sometimes caused noticeable freezes when opening child windows like DatabaseSelectWindow. We mitigated this by throttling and batching UI telemetry updates and dispatching them at DispatcherPriority.Background while ensuring the final state always flushes on completion.

Quirks

Packaging self-contained builds from a Linux CI environment for Windows, Linux, and macOS surfaced subtle runtime differences. For macOS, single-file publishing (-p:PublishSingleFile=true) led to the executable not being able to resolve libSkiaSharp at launch so we fixed this by disabling single-file publishing for macOS and bundling the native libraries with the executable.

Because open-source builds without a paid Apple Developer ID are flagged as "damaged" when downloaded, we automated a Homebrew Cask updater directly in our GitHub Actions release pipeline alongside a terminal installer script (install_mac.sh) so macOS users on Intel, M-series, and MacBook Neo machines get a zero-friction installation. This was basically a kind of band-aid solution