﻿<?xml version="1.0" encoding="utf-8"?><rss version="2.0"><channel><title>Ayende @ Rahien</title><link>http://ayende.com</link><description>Ayende @ Rahien</description><copyright>Copyright (C) Ayende Rahien  2004 - 2021 (c) 2026</copyright><ttl>60</ttl><item><title>Ale Miralles commented on Compare and contrast: Performance implications of method signatures</title><description>It wouldn't be the same, calling the FirstSignature.Take(2) using linq? 
I mean, the execution will be deferred and you only will take what you need. (assuming you are use yield return inside both methods)</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment20</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment20</guid><pubDate>Tue, 03 Apr 2012 12:31:18 GMT</pubDate></item><item><title>Vovik Bilyachat commented on Compare and contrast: Performance implications of method signatures</title><description>Second option is much more better specially if database holds lots of data.
I am using in quite different way, 
Method(int id, int page, int perpage=10),
</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment19</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment19</guid><pubDate>Tue, 03 Apr 2012 07:39:25 GMT</pubDate></item><item><title>Matt Johnson commented on Compare and contrast: Performance implications of method signatures</title><description>It we're talking about RavenDB, you recently taught me about the result set being limited to 128 results unless you specify a Take, in which case it can go to 1024 results.  By requiring Take as a parameter, you enforce it being entered by the caller, and you can choose to validate that it's not larger than 1024, throwing an exception if it is.

If we're just talking about c# method signatures, I would guess that an extra parameter means more IL, but I don't know that I'd consider that a perf issue.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment18</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment18</guid><pubDate>Mon, 02 Apr 2012 19:58:22 GMT</pubDate></item><item><title>Chad Moran commented on Compare and contrast: Performance implications of method signatures</title><description>Since the methods have less than 2 params can't they be used with x86 Fastcall?

Maybe I'm over thinking it but I've had a lot of experience with x86.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment17</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment17</guid><pubDate>Mon, 02 Apr 2012 16:31:32 GMT</pubDate></item><item><title>Dathan commented on Compare and contrast: Performance implications of method signatures</title><description>The second set make paging an explicit concept, whereas the first do not.  If these methods are retrieving data from a server, the first set either a) gets ALL results in a single pass, b) implements some paging transparently, or c) makes a server call for each successive result (which is just paging with a page size of 1).  In case (a), it's *probably* more results than the user really wants.  In case (b), it's very unlikely (unless configurable via some other call) that the internal page size is optimal for the caller's purposes.  And (c) is almost certain to be suboptimal.  

There's no guarantee that the second set of methods perform filtering server side (if there IS a server involved).  But they make server-side filtering a possibility, whereas the first do not (or at least, don't encourage it).

By forcing the caller to think about paging, we're more likely to encourage correct use.  e.g., the developer might think, "Do I really need more than one page?" or "I should display one page, and then only load an additional page if necessary," while the first set does nothing to actively encourage that sort of thinking.

The caller is more likely to use an optimal or nearly-optimal page size in the second version, which (again, IF server-side filtering is enabled) will mean more efficient use of resources.

And @Eber, there's no reason you have to respect a call with take=Int32.MaxValue.  You can impose a maximum result set size in the second method set as easily as in the first.  Perhaps *more* easily (from a usage point of view), since the caller is already expecting to only get a certain number of results per call when using the second set, whereas s/he could reasonably expect to be able to iterate over all results in the first set.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment16</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment16</guid><pubDate>Mon, 02 Apr 2012 16:06:59 GMT</pubDate></item><item><title>Richard Wilde commented on Compare and contrast: Performance implications of method signatures</title><description>The second one is allowing the user to specify a really LARGE number say 1,000,000,000 which has its own problems.
</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment15</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment15</guid><pubDate>Mon, 02 Apr 2012 16:01:48 GMT</pubDate></item><item><title>Mark J. Miller commented on Compare and contrast: Performance implications of method signatures</title><description>One phrase: bounded result sets. Oren has tried to hammer this concept home for a long time.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment14</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment14</guid><pubDate>Mon, 02 Apr 2012 15:44:20 GMT</pubDate></item><item><title>Eber Irigoyen commented on Compare and contrast: Performance implications of method signatures</title><description>that's funny that so far everyone sees the second as "safe by default", you're just thinking about one case, but you're giving the user the chance to (abuse) specify how much they want, where on the first one, you can decide what "safe by default" means, the second one is just giving more responsibility to the user</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment13</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment13</guid><pubDate>Mon, 02 Apr 2012 15:39:08 GMT</pubDate></item><item><title>Christopher Wright commented on Compare and contrast: Performance implications of method signatures</title><description>Making the page size parameter explicit means less overhead. For a UI, you might want a page size of 20, since you're only displaying 20 records to the user; if it's hard-coded to 100, you retrieve a lot more each time than you need. For batch processing, you want a much higher page size, and end up making more calls to the server than you would otherwise.

Since this is using IEnumerable, the pagination might be implicit rather than requiring additional calls, but the principle is the same.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment12</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment12</guid><pubDate>Mon, 02 Apr 2012 15:24:49 GMT</pubDate></item><item><title>Matt Davey commented on Compare and contrast: Performance implications of method signatures</title><description>The only facts we can take from the code sample without making any assumptions is that the second set of methods are having to copy an extra value type parameter - which will degrade performance albeit in a negligible way. Any other conclusion we draw is based on assumptions which may not hold true.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment11</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment11</guid><pubDate>Mon, 02 Apr 2012 13:23:37 GMT</pubDate></item><item><title>Peter Morlion commented on Compare and contrast: Performance implications of method signatures</title><description>Xing Yang and Lee Atkinson are right. Plus, nothing prevents a consumer of this API of passing int.MaxValue to get as many records as he/she can.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment10</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment10</guid><pubDate>Mon, 02 Apr 2012 11:32:45 GMT</pubDate></item><item><title>Fabse commented on Compare and contrast: Performance implications of method signatures</title><description>the second version is safe-by-default against unbounded result lists.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment9</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment9</guid><pubDate>Mon, 02 Apr 2012 11:28:18 GMT</pubDate></item><item><title>Giorgi commented on Compare and contrast: Performance implications of method signatures</title><description>The later one allows the server to read only 'take' records from data source while the former does not make any restrictions and can result in unbound result set.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment8</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment8</guid><pubDate>Mon, 02 Apr 2012 11:15:33 GMT</pubDate></item><item><title>Lee Atkinson commented on Compare and contrast: Performance implications of method signatures</title><description>A lot of people have talked about 'on the server' - where in the post does it mention anything about a server?

If we take the methods as stated, we cannot say for certain what the implication are. If the implementations rely on streaming of object (i.e. IEnumerables 'all the way down'), then the second set it possibly slightly less performant as we have an extra argument to pass and check (e.g. &gt; 0).

If the implmentations do involve batch processing of objects (i.e. loading from an external service in groups rather than streaming), or they rely on a service that can perform better knowing the 'take' then it's possible they will perform better knowing that how many the consuming code will require.

Without the implmentation, it's impossible to say. I would have the most appropriate and only add the other if testing proves advantageous.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment7</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment7</guid><pubDate>Mon, 02 Apr 2012 11:06:53 GMT</pubDate></item><item><title>Xing Yang commented on Compare and contrast: Performance implications of method signatures</title><description>They both have the same performance implication to the client as they all returning IEnumberable&lt;&gt; so it's up to the implementation to decide how to feed the enumerator.

Even without "take" parameter in the first set of APIs, it's understandable it may have internal paging mechanisms. The APIs themselves just doesn't promise anything.

I'd make the API to return IQueryable&lt;&gt; to imply better performance characteristics. As IQueryable&lt;&gt; suggests the query will be deferred when a complete query spec is available (e.g. with all filters, projections and paging ready). This way it's up to the client to decide how to achieve the best performance with its own specific requirement.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment6</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment6</guid><pubDate>Mon, 02 Apr 2012 10:49:32 GMT</pubDate></item><item><title>Petar Repac commented on Compare and contrast: Performance implications of method signatures</title><description>The latter mathod signatures are stimulating the developer to give more insight to how many documents are expected. This then allows the server to perform better.

After returning "take" documents, server doesn't need to scan for other candidates any more. Also it would not return extra data ower network.

I suspect the API doesn't do stream, but retrieves whole result set and then presents it as IEnumerable. Otherwise every "fetch" from IEnumerable would be possibly an network round trip.
</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment5</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment5</guid><pubDate>Mon, 02 Apr 2012 10:26:13 GMT</pubDate></item><item><title>Falhar commented on Compare and contrast: Performance implications of method signatures</title><description>First always returns all items. Even when we dont need them. Filtering is done on the client.

Second returns only returns items we need. Filtering is done on the server, thus saving bandwidth.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment4</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment4</guid><pubDate>Mon, 02 Apr 2012 10:19:07 GMT</pubDate></item><item><title>James Newton-King commented on Compare and contrast: Performance implications of method signatures</title><description>They both return IEnumerable so I assume they both stream. The only difference I imagine is that the second will stop returning results once the "take" limit is reached, something someone could probably simulate by calling the first not iterating after a certain number of results.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment3</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment3</guid><pubDate>Mon, 02 Apr 2012 10:10:35 GMT</pubDate></item><item><title>Rinat Abdullin commented on Compare and contrast: Performance implications of method signatures</title><description>Second option can inherently be more performant - "take" is a hint for server.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment2</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment2</guid><pubDate>Mon, 02 Apr 2012 10:07:07 GMT</pubDate></item><item><title>Felice Pollano commented on Compare and contrast: Performance implications of method signatures</title><description>Not sure I get the question completely, but the second version limit the resultset ( a thing we almost always need ) while the first don't.</description><link>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment1</link><guid>http://ayende.com/154497/compare-and-contrast-performance-implications-of-method-signatures#comment1</guid><pubDate>Mon, 02 Apr 2012 10:04:00 GMT</pubDate></item></channel></rss>