C# matches C in VLC's Gaussian blur, reaching 236 fps versus 240

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

C# matches C in VLC's Gaussian blur, reaching 236 fps versus 240

Martin Finkel ported VLC's Gaussian blur filter line by line to C# using .NET Native AOT, then raced both versions inside the same VLC on identical 1080p frames. The straight port ran about 23% slower, largely because RyuJIT does less than clang on tight loops; two small edits closed most of that gap. After optimizing both with the same algorithm and then AVX2 SIMD, the C# version reached 236 fps at sigma 4 against C's 240, roughly 30 times faster than VLC's current code.

Part of that work was rewriting C# so .NET emits what clang emits by default. That is the real cost of choosing C# here: knowing what the compiler does with your loops.
  1. teo_zero

    Nice article!

    What surprises me is that the original VLC filter does not use SIMD. Sometimes I wonder why I spent my money on a "modern" CPU with a lot of new features that stay completely ignored by most software I run every day.

  2. tinykerneldev

    Interesting. Even more interesting would have been seeing if/how C# SIMD intrinsics would have improved performance.

  3. theanonymousone

    > Two small edits close most of it: compute the loop bounds into locals before the loop,

    I always assumed any decent runtime/compiler takes care of such optimisations, and usually leave such things to JDK in my Java code. Is that really not the case?

  4. brookman64k

    I would have expected the filters to run as a shader on the GPU which would make them much more efficient.

    I remember implementing two-pass gaussian blur in GLSL almost 20 years ago.

  5. anderskaseorg

    There are much faster algorithms available for Gaussian blur though, running in O(n) rather than O(nσ) for an n pixel image and radius σ. See https://www.ipol.im/pub/art/2013/87/article.pdf for a survey.

More from this day

2026-10-24