<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'><id>tag:blogger.com,1999:blog-8486822413101972100.post759734529913868582..comments</id><updated>2009-02-22T18:43:52.960+05:00</updated><title type='text'>Comments on .NET tips, tricks and patterns: The cost of method calls</title><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://tips.x-tensive.com/feeds/759734529913868582/comments/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html'/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>6</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-6648387004506486060</id><published>2009-02-22T18:43:52.960+05:00</published><updated>2009-02-22T18:43:52.960+05:00</updated><title type='text'>A report about mentioned issue with performance of...</title><content type='html'>A report about mentioned issue with performance of VGM calls on interface: https://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=91710</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/6648387004506486060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/6648387004506486060'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1235310232960#c6648387004506486060' title=''/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09650213915253068470'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-2773055778086838405</id><published>2009-02-22T18:41:11.689+05:00</published><updated>2009-02-22T18:41:11.689+05:00</updated><title type='text'>An overview of implementation of virtual generic m...</title><content type='html'>An overview of implementation of virtual generic method call in Mono: http://schani.wordpress.com/2008/10/12/fast-virtual-generic-calls/</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/2773055778086838405'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/2773055778086838405'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1235310071689#c2773055778086838405' title=''/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09650213915253068470'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-6242380767525323938</id><published>2008-11-01T21:29:17.902+05:00</published><updated>2008-11-01T21:29:17.902+05:00</updated><title type='text'>Copying recent discussion of this post by e-mail:Q...</title><content type='html'>Copying recent discussion of this post by e-mail:&lt;BR/&gt;&lt;BR/&gt;&lt;B&gt;Q:&lt;/B&gt; &lt;I&gt;Hello Alex,&lt;BR/&gt;&lt;BR/&gt;I have read your blog post "The cost of method calls". It's very interesting. I was very surprised on the cost of virtual generic method call. Isn't there any difference between using reference vs value type parameters on the type or method?&lt;/I&gt;&lt;BR/&gt;&lt;BR/&gt;&lt;B&gt;A:&lt;/B&gt;&lt;BR/&gt;&lt;BR/&gt;I suspect there can be noticeable difference: since actually there is just one JITted version of method emitted for any reference type, theoretically it can be found much faster (i.e. without a hash table lookup).&lt;BR/&gt;&lt;BR/&gt;On the other hand, generic methods are practically much more interesting for value types... For reference types they bring only better safety &amp;amp; readability. That&amp;#39;s why we measured this for value types only.&lt;BR/&gt;&lt;BR/&gt;So just measured:&lt;BR/&gt;&lt;BR/&gt;Virtual generic call test (1 generic argument: Int32):&lt;BR/&gt;  Type: Int32&lt;BR/&gt;  Measurement: Generic method 1 (class)                  &lt;B&gt;65,500 M/s.&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (class, by delegate)     403,042 M/s.&lt;BR/&gt;  Measurement: Generic method 1 cast (class)             &lt;B&gt;42,202 M/s.&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (interface)              &lt;B&gt;65,523 M/s.&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (interface, by delegate) 405,369 M/s.&lt;BR/&gt;  Measurement: Generic method 1 cast (interface)         &lt;B&gt;&lt;I&gt;609,802 K/s.&lt;/I&gt;&lt;/B&gt;&lt;BR/&gt;Virtual generic call test (1 generic argument: String):&lt;BR/&gt;  Type: String&lt;BR/&gt;  Measurement: Generic method 1 (class)                  &lt;B&gt;51,888 M/s.&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (class, by delegate)     308,143 M/s.&lt;BR/&gt;  Measurement: Generic method 1 cast (class)             &lt;B&gt;&lt;I&gt;444,508 K/s.&lt;/I&gt;&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (interface)              &lt;B&gt;51,326 M/s.&lt;/B&gt;&lt;BR/&gt;  Measurement: Generic method 1 (interface, by delegate) 309,349 M/s.&lt;BR/&gt;  Measurement: Generic method 1 cast (interface)         &lt;B&gt;&lt;I&gt;443,909 K/s.&lt;/I&gt;&lt;/B&gt;&lt;BR/&gt;&lt;BR/&gt;Conclusions:&lt;BR/&gt;- The difference is generally neglectable. May be we should try putting "where T: class" constraint on such methods to make JITter to think about this a bit more? ;)&lt;BR/&gt;- Again, it seems there is a serious bug in delegate creation (see bold italicized results in "... cast" lines).</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/6242380767525323938'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/6242380767525323938'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1225556957902#c6242380767525323938' title=''/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09650213915253068470'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-1116911481848624718</id><published>2008-10-29T13:46:55.836+05:00</published><updated>2008-10-29T13:46:55.836+05:00</updated><title type='text'>I agree with this. Anonymous delegates are frequen...</title><content type='html'>I agree with this. Anonymous delegates are frequently not cached, and in such cases construction of their instances is rather costly. Let's estimate this:&lt;BR/&gt;&lt;BR/&gt;- .NET creates an anonymous type to handle such a delegate. Its construction cost is ~ 3.5 in comparison to VM call.&lt;BR/&gt;- Then it creates a delegate pointing to its method. The cost is ~ 7.5.&lt;BR/&gt;- Finally, it invokes it. The cost is 1.5, assuming invocation happens just once (i.e. the worst, but most likely the most common case).&lt;BR/&gt;&lt;BR/&gt;So if anonymous delegate is called just once, you're getting ~ 8.5 times slower call in case it isn't cached.&lt;BR/&gt;&lt;BR/&gt;In general this isn't "to bad" - i.e. you should have about 50M invocations \ second in such a case. This is anyway much more then such languages as Ruby or Python may provide. But less then 400M with a regular delegate, of course ;)&lt;BR/&gt;&lt;BR/&gt;Btw, this is enough for the most of RDBMS \ BLL related tasks. &lt;A HREF="http://wiki.dataobjects.net/index.php?title=Benchmark%2C_October_1%2C_2008" REL="nofollow"&gt;It was shown&lt;/A&gt; that peak speed of data extraction with ORM is about 400K instances per second, i.e. 100 times slower. So using such anonymous delegates won't seriously affect on performance in such cases.&lt;BR/&gt;&lt;BR/&gt;But if I develop a game on C#, or something else requiring real-time computing, I would seriously care about this.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/1116911481848624718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/1116911481848624718'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1225270015836#c1116911481848624718' title=''/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09650213915253068470'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-5622710836085857060</id><published>2008-10-29T13:14:44.029+05:00</published><updated>2008-10-29T13:14:44.029+05:00</updated><title type='text'>Good stuff, Alex.What do you think of functional-s...</title><content type='html'>Good stuff, Alex.&lt;BR/&gt;&lt;BR/&gt;What do you think of functional-style programming in C# 3.0 and anonymous delegates? It seems that it will generate slower programs without the developer's knowledge... It is maybe the natural path from a low-level and efficient programming language to a high-level and low one :(.&lt;BR/&gt;&lt;BR/&gt;-gael</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/5622710836085857060'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/5622710836085857060'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1225268084029#c5622710836085857060' title=''/><author><name>Gael Fraiteur</name><uri>http://www.blogger.com/profile/17671667711872654572</uri><email>noreply@blogger.com</email></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry><entry><id>tag:blogger.com,1999:blog-8486822413101972100.post-71686650879066254</id><published>2008-10-29T12:29:56.083+05:00</published><updated>2008-10-29T12:29:56.083+05:00</updated><title type='text'>Forgot to add: the code for all these tests can be...</title><content type='html'>Forgot to add: the code for all these tests can be found in &lt;A HREF="http://www.x-tensive.com/Downloads/?Path=DataObjects.Net_4" REL="nofollow"&gt;DataObjects.Net 4.0&lt;/A&gt; test suite, see "Xtensive.Core\Xtensive.Core.Tests\DotNetFramework\".&lt;BR/&gt;&lt;BR/&gt;Any comments are welcome.</content><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/71686650879066254'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/8486822413101972100/759734529913868582/comments/default/71686650879066254'/><link rel='alternate' type='text/html' href='http://tips.x-tensive.com/2008/10/method-call-performance.html?showComment=1225265396083#c71686650879066254' title=''/><author><name>Alex Yakunin</name><uri>http://www.blogger.com/profile/13800929290476802273</uri><email>noreply@blogger.com</email><gd:extendedProperty xmlns:gd='http://schemas.google.com/g/2005' name='OpenSocialUserId' value='09650213915253068470'/></author><thr:in-reply-to xmlns:thr='http://purl.org/syndication/thread/1.0' href='http://tips.x-tensive.com/2008/10/method-call-performance.html' ref='tag:blogger.com,1999:blog-8486822413101972100.post-759734529913868582' source='http://www.blogger.com/feeds/8486822413101972100/posts/default/759734529913868582' type='text/html'/></entry></feed>