hn.today

C vs. C#: racing VLC's Gaussian blur

martinfinkel.com5 points0 comments
Screenshot of C vs. C#: racing VLC's Gaussian blur

This compares a line-by-line C# port of VLC’s Gaussian blur filter to the original C implementation and measures why and how much they differ. The blur is separable (horizontal then vertical), VLC’s original uses integer arithmetic and two-pass buffering, and the C# version is compiled with .NET Native AOT so it runs as a native VLC plugin and produces byte-identical frames on the same 1080p test clip on an 11th‑gen Core i7. The initial unoptimized C# port ran about 23% slower per frame than C; profiling showed the difference came from code generation (RyuJIT emitted more instructions, re-evaluating loop bounds and keeping sums in memory) rather than garbage collection or bounds checks.

Targeted changes and SIMD tuning closed almost all of that gap. Simple edits (precompute loop bounds, use nint) brought the line-by-line port within 8% of C, and further vectorized rewrites produced near-parity SIMD builds: tuned C ran ~3.05-6.62 ms/frame and tuned C# ~3.05-7.22 ms/frame, yielding about 240 vs 236 fps at sigma 4. The experiment shows C# is a realistic CPU-side choice when optimized against the JIT’s quirks, but C retains the final edge for the last 10% of performance. The work also exposed two VLC bugs and the filter is available in VLCLR.Filters for further testing.

Read on martinfinkel.com0 comments on Hacker News

Summary generated by AI from the linked article. hn.today is not affiliated with Hacker News or Y Combinator.

More in Programming

We have traits at home

We have traits at home

Zig uses two main approaches for polymorphism: runtime interfaces with dynamic dispatch and compile-time duck typing for static polymorphism. These methods offer different tradeoffs in performance and safety, with Zig emphasizing simplicity and compile-time checks over complex abstractions. (axelmagn.com)

The daily digest

Today's best Hacker News stories, summarized and screenshotted, one email a day.