{"action":"opened","issue":{"url":"https://api.github.com/repos/dotnet/coreclr/issues/14957","repository_url":"https://api.github.com/repos/dotnet/coreclr","labels_url":"https://api.github.com/repos/dotnet/coreclr/issues/14957/labels{/name}","comments_url":"https://api.github.com/repos/dotnet/coreclr/issues/14957/comments","events_url":"https://api.github.com/repos/dotnet/coreclr/issues/14957/events","html_url":"https://github.com/dotnet/coreclr/issues/14957","id":272490912,"number":14957,"title":"[JIT] ref return indexing into array runs more slowly than non-ref return","user":{"login":"damageboy","id":125730,"avatar_url":"https://avatars3.githubusercontent.com/u/125730?v=4","gravatar_id":"","url":"https://api.github.com/users/damageboy","html_url":"https://github.com/damageboy","followers_url":"https://api.github.com/users/damageboy/followers","following_url":"https://api.github.com/users/damageboy/following{/other_user}","gists_url":"https://api.github.com/users/damageboy/gists{/gist_id}","starred_url":"https://api.github.com/users/damageboy/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/damageboy/subscriptions","organizations_url":"https://api.github.com/users/damageboy/orgs","repos_url":"https://api.github.com/users/damageboy/repos","events_url":"https://api.github.com/users/damageboy/events{/privacy}","received_events_url":"https://api.github.com/users/damageboy/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":0,"created_at":"2017-11-09T09:19:45Z","updated_at":"2017-11-09T09:19:45Z","closed_at":null,"author_association":"NONE","body":"Basically trying to test the diffrence between:\r\n\r\nCode is [here](https://github.com/damageboy/refslowness)\r\n\r\nPlain vanilla indexing into array:\r\n```c#\r\n    public T this[int index]\r\n    {\r\n      [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n      get\r\n      {\r\n#if DEBUG\r\n        if (index < 0 || index >= Count)\r\n          throw new ArgumentOutOfRangeException(nameof(index), $\"Bad index {index} was supplied, Count is {Count}\");\r\n        if (Count != Capacity)\r\n          throw new InvalidOperationException(\"The indexer may not be called before the buffer is full\");\r\n#endif\r\n\r\n        return _buffer[(_head + index) % Capacity];\r\n      }\r\n    }\r\n```\r\n\r\nAnd a ref version of the same thing:\r\n```c#\r\n    public ref T this[int index]\r\n    {\r\n      [MethodImpl(MethodImplOptions.AggressiveInlining)]\r\n      get\r\n      {\r\n#if DEBUG\r\n        if (index < 0 || index >= Count)\r\n          throw new ArgumentOutOfRangeException(nameof(index), $\"Bad index {ind                            ex} was supplied, Count is {Count}\");\r\n        if (Count != Capacity)\r\n          throw new InvalidOperationException(\"The indexer may not be called be                            fore the buffer is full\");\r\n#endif\r\n\r\n        return ref _buffer[(_head + index) % Capacity];\r\n      }\r\n    }\r\n```\r\n\r\n# Non ref:\r\nBenchmarkDotNet=v0.10.10, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.19)\r\nProcessor=Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), ProcessorCount=8\r\nFrequency=2742186 Hz, Resolution=364.6726 ns, Timer=TSC\r\n.NET Core SDK=2.0.2\r\n  [Host]     : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT\r\n  Job-THPAEG : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2556.0\r\n\r\nJit=RyuJit  Platform=X64  Runtime=Clr\r\nLaunchCount=1  TargetCount=10  WarmupCount=1\r\n\r\n  Method |     Mean |     Error |    StdDev |      Min |      Max |\r\n-------- |---------:|----------:|----------:|---------:|---------:|\r\n Indexer | 2.290 ns | 0.0441 ns | 0.0291 ns | 2.240 ns | 2.327 ns |\r\n \r\n # Ref\r\n \r\n \r\nBenchmarkDotNet=v0.10.10, OS=Windows 10 Redstone 3 [1709, Fall Creators Update] (10.0.16299.19)\r\nProcessor=Intel Core i7-7700HQ CPU 2.80GHz (Kaby Lake), ProcessorCount=8\r\nFrequency=2742186 Hz, Resolution=364.6726 ns, Timer=TSC\r\n.NET Core SDK=2.0.2\r\n  [Host]     : .NET Core 2.0.0 (Framework 4.6.00001.0), 64bit RyuJIT\r\n  Job-LVZAAF : .NET Framework 4.7 (CLR 4.0.30319.42000), 64bit RyuJIT-v4.7.2556.0\r\n\r\nJit=RyuJit  Platform=X64  Runtime=Clr\r\nLaunchCount=1  TargetCount=10  WarmupCount=1\r\n\r\n  Method |     Mean |     Error |    StdDev |      Min |      Max |\r\n-------- |---------:|----------:|----------:|---------:|---------:|\r\n Indexer | 3.468 ns | 0.1724 ns | 0.1141 ns | 3.361 ns | 3.683 ns |\r\n\r\n\r\nAs faras I can see, there is no real reason for why the ref-return version run slowly compared to the non-ref version...\r\n\r\nIn theory, ref-return should/could just do the pointer calculation and the caller would do the derefefrence just like the non ref version..."}}
{"actor":{"display_login":"damageboy"}}