Skip to content

Conversation

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Nov 2, 2025

It seems that lock()'s bottleneck (no contention, ThinLock) is CompareExchange. Since it's a Thin Lock we effectively know there is no thread contention. It seems like in that case we might want to avoid LSE outlining since LSE is more about high-contention scenarios.

this is a no-merge PR, just to run a benchmark.

@github-actions github-actions bot added the needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners label Nov 2, 2025
@EgorBo

This comment was marked as resolved.

@EgorBo
Copy link
Member Author

EgorBo commented Nov 2, 2025

@EgorBot -azure_cobalt100 -azure_ampere -aws_graviton3 -aws_graviton4 -gcp_axion

using System.Runtime.CompilerServices;
using BenchmarkDotNet.Attributes;

public class Benchmark
{
    static readonly object SyncRoot = new();

    [Benchmark]
    public void Object()
    {
        lock (SyncRoot)
            DoWork();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void DoWork() { }
}

@EgorBo
Copy link
Member Author

EgorBo commented Nov 3, 2025

looks like it does improve perf on all arm cpus: EgorBot/runtime-utils#536

@EgorBo EgorBo closed this Nov 3, 2025
@jkotas
Copy link
Member

jkotas commented Nov 3, 2025

LSE is more about high-contention scenarios

LSE is also about less expensive memory barriers. The perf results may be different once you do a bunch of memory reads and writes on both inside and outside the lock to mimic more realistic scenario, and the more expensive memory barrier in non-LSE variant has actual work to do.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

needs-area-label An area label is needed to ensure this gets routed to the appropriate area owners

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants