﻿<?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>Daniel commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>If a delegate closes over local variables, a helper class gets created, so a lambda translates into 2 allocations: the helper class and the delegate.
  
  
If a delegate closes only over 'this', it gets compiled into an instance method. These aren't cached, so the lambda causes 1 allocation: the delegate.
  
  
If a delegate doesn't close over any variables, then it gets compiled into a static method, and the delegate gets cached using a static field. Once the cache is filled, the lambda doesn't cause any heap allocations.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment7</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment7</guid><pubDate>Thu, 14 Oct 2010 14:36:22 GMT</pubDate></item><item><title>Matt Warren commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>@configurator I *think* that if it uses fields it gets converted into a instance method, but I'm not entirely sure.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment6</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment6</guid><pubDate>Wed, 13 Oct 2010 23:53:27 GMT</pubDate></item><item><title>configurator commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>Tobi is right. Non-closing delegates are converted to static methods. I don't know what happens to ones that use fields, but I'm pretty sure they're cached as well. Only when closing over locals you're creating a mess.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment5</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment5</guid><pubDate>Wed, 13 Oct 2010 17:41:13 GMT</pubDate></item><item><title>Dennis commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>Even so, the speed at which this allocation happens makes it just an insane micro optimization... Unless you are doing it billions of times.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment4</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment4</guid><pubDate>Wed, 13 Oct 2010 12:03:07 GMT</pubDate></item><item><title>tobi commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>No! I think the C# compiler caches delegates that do not close over variables. I have seen that in reflector a while ago. The delegate gets written to a static field.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment3</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment3</guid><pubDate>Wed, 13 Oct 2010 10:27:12 GMT</pubDate></item><item><title>Ayende Rahien commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>Well, that was fast.
  
Yep, that is it.
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment2</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment2</guid><pubDate>Wed, 13 Oct 2010 10:24:09 GMT</pubDate></item><item><title>Torkel commented on Small optimizations? Did you check that idiot checkbox yet?</title><description>Instead of newing a List you new up a delegate each call to GetOrAdd ?
</description><link>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment1</link><guid>http://ayende.com/4660/small-optimizations-did-you-check-that-idiot-checkbox-yet#comment1</guid><pubDate>Wed, 13 Oct 2010 10:21:40 GMT</pubDate></item></channel></rss>