Showing posts with label .NET. Show all posts
Showing posts with label .NET. Show all posts
Sunday, 25 October 2009
Release it! - some loose thoughts
I’ve been trying to finish that book for quite some time. It was difficult :) because it is a book that you can read chapter by chapter without losing the plot and hence it’s easy to abandon it every now and then. Anyway, I managed to finish it this week and I have to say that I haven’t really learnt anything new. This doesn’t mean that it was a waste of time. On the contrary, after reading it I’m more confident that what I’ve been doing is right and I’m not some kind of weirdo that demands the impossible :). It’s definitively a must read for developers that haven’t worked in 24/7 environment where part of their job is to be on call for a week every month or two. When you can get a call at 3 am you design your software in a little bit different way :). I will dedicate a separate post to that topic.
There is one thing in the book that I disagree with though. Page 199, Michael recommends to use SoftReference when implementing a cache in Java. The counterpart of SoftReference in .NET world is WeakReference. I think that is a very bad idea. The most important part of every caching solution is its expiration policy which would translate to a simple question – when does the data need to be refreshed? GC operates at a very low level and it doesn’t have enough information to make an informed decision. Let me give you an example. Let’s say we have 2 arrays of integers(System.Int32). Both of them 1000 elements long and it takes 10 ms to fill the first one and 100 sec to fill the second one and they both need to be refreshed once an hour. From GC perspective they are basically the same objects. It doesn’t matter which one gets collected as in both cases GC will reclaim 4000 bytes. This is not true from the application perspective. If GC decides to release often the memory associated with the second array the application will crawl. If not it will be lightning fast. What if the GC implementation changes and after upgrade to the next version of the runtime the performance of the app changes completely. I wouldn’t like to debug this problem. In other words, you can’t build a solution that needs to be predictable(cache expiration policy) based on a component (GC) that is beyond your control.
There is one thing in the book that I disagree with though. Page 199, Michael recommends to use SoftReference when implementing a cache in Java. The counterpart of SoftReference in .NET world is WeakReference. I think that is a very bad idea. The most important part of every caching solution is its expiration policy which would translate to a simple question – when does the data need to be refreshed? GC operates at a very low level and it doesn’t have enough information to make an informed decision. Let me give you an example. Let’s say we have 2 arrays of integers(System.Int32). Both of them 1000 elements long and it takes 10 ms to fill the first one and 100 sec to fill the second one and they both need to be refreshed once an hour. From GC perspective they are basically the same objects. It doesn’t matter which one gets collected as in both cases GC will reclaim 4000 bytes. This is not true from the application perspective. If GC decides to release often the memory associated with the second array the application will crawl. If not it will be lightning fast. What if the GC implementation changes and after upgrade to the next version of the runtime the performance of the app changes completely. I wouldn’t like to debug this problem. In other words, you can’t build a solution that needs to be predictable(cache expiration policy) based on a component (GC) that is beyond your control.
Wednesday, 1 October 2008
Dublin - it's not a city it's a new Microsoft codename :)
It looks like Windows Server 2008 needs to be extended to be able to host WCF 4.0 and WF 4.0 type of applications. The codename of this set of extensions is called Dublin. Dublin is the capital of Ireland and I'm curious if the author of the codename knew about that. Anyway, you can find more details about the new platform here. At the first glance it looks interesting but still there is no mention of publish/subscribe type of messaging. I hope I've missed something as this a huge gap in the communication framework that Microsoft provides.
Friday, 29 August 2008
27 stack frames on 32 bit OS and 22 stack frames on 64 bit OS
64 bit JIT and 32 bit JIT are 2 very different beasts which is what one would suspect. But still I was rather surprised that 64 bit JIT was able to reduce the call stack of a call by 20% in comparison with 32 bit JIT. A piece of my code crawls the call stack to gather some runtime characteristics and it broke on a 64 bit machine. That's how I started a small investigation and found this difference. In most cases it's not a good idea to rely on the way JIT works as this is subject to change but from time to time there is simply no other way. If you look for more information about 32/64 JIT you can check this blog post of Scott Hanselman which is an overview with links to other Microsoft bloggers that dive much deeper into details.
Monday, 30 June 2008
A setting that can boost performance of any heavily network-dependent application
By default .NET allows only 2 connections to a given network address per AppDomain. In most cases this works fine but if your app makes a couple of dozens network calls a second then this value might be too small and it might actually cause a bottleneck that is very hard to diagnose. I decided to increase the value of this setting to the value that is recommend by Microsoft (number_of_cores x 12) and one of my services speeded up significantly. Having said that I have to stress that there is no guarantee this setting will work in your case. Remember, measure, measure and once again measure when you optimize.
And the setting is:
And the setting is:
<system.net>
<connectionManagement>
<add address="*" maxconnection="96"/>
</connectionManagement>
</system.net>
Wednesday, 28 November 2007
LINQ and its diverse incarnations
LINQ as a concept is highly extensible and every now and then a new LINQ to WhatEverYouWant gets announced. Just a few examples to show how fast people are adopting this technology: LINQ to LLBLGEN, LINQ to NHibernate, LINQ to Filckr, LINQ to Amazon, etc. Within a few days I've come across 3 more projects:
- SyncLinq - it returns collections that implement
INotifyCollectionChangedwhich lets you track changes - PLinq - it lets you specify that a given LINQ statement should be executed concurrently and it's up to the runtime to decide how many CPUs will be used
- DryadLinq - the same as PLinq, just replace CPU with PC, basically it lets you specify that your query should be executed on many machines
Tuesday, 20 November 2007
I can use Microsoft Surface but I can not nest directories as deep as I want
Microsoft Research is surprising us nearly every month. Just to name a few of their great products: PhotoSynth and Microsoft Surface. But you know what every day I hit the #$%@ limitation on the length of the path. 260 characters and that's all I can get in the .NET framework. Guys, can we back up a bit and solve the basic problems?
Resharper - click on the picture to see the details:
MsBuild - click on the picture to see the details:
Resharper - click on the picture to see the details:
MsBuild - click on the picture to see the details:
Friday, 5 October 2007
Microsoft .NET framework goes open source - kind of :)
Scott Guthrie doesn't stop surprising me. Nearly every month he publishes something that makes me think that Microsoft is not that bad at all :). Today topic is the .NET source code. One could say that Reflector provides that functionality since it came out. That's true but Microsoft goes beyond that and they actually integrate debugging symbols + source code with VS.NET 2008. This feature will let you seamlessly step into the .NET framework code while you debug your own application. What is more they provide code with all the comments which from time to time can make huge difference. Of course they don't go mad completely and the licence the code will be released under prevents you from copying it. No hope for a quick catch up for Mono :).
Friday, 21 September 2007
You can't get rid of memory leaks
There are still people out there who think that by having GC they don't have to bother about memory leaks. Well that's not entirely true. I would even say that's a false statement. Next time someone says something like that I will send him/her to Mike Stall
Sunday, 16 September 2007
Voice of the Silverlight team in Dublin
Martha Rotter will be presenting Silverlight in Dublin on 27th of September. It might be interesting, depends how deep she wants to dive :).
Friday, 20 July 2007
Dynamic nature of C# I bet you don't know :)
Yesterday I read a blog post that meant to discuss possible naming conventions for LINQ but it turned out that the most interesting part of it was something completely different. Namely, Krzysztof Cwalina wrote that we don't have to implement IEnumerable and IEnumerator to be able to iterate through an object(collection) using foreach statement. It's enough that a class exposes GetEnumerator() method. It doesn't have to implement IEnumerable interface. At the beginning I thought that it's just another example of syntactic sugar and that the C# compiler generates implicit IEnumerable declaration on our behalf. But then I opened ildasm.exe and saw that that's not the case. IEnumerable wasn't there. That's it. Have a look at the code snippet and screen shot below to check it out.
The bottom line is that I learn every day and .NET doesn't stop surprising me which is fun :).
EDIT: I've modified the image because it looked horrible.
The bottom line is that I learn every day and .NET doesn't stop surprising me which is fun :).
EDIT: I've modified the image because it looked horrible.
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
class Program
{
static void Main(string[] args)
{
FakeEnumerableClass enumerable = new FakeEnumerableClass();
foreach (object o in enumerable)
{
//works perfectly fine :)
}
}
}
class FakeEnumerableClass
{
public FakeEnumerator GetEnumerator()
{
return new FakeEnumerator();
}
}
public class FakeEnumerator
{
public bool MoveNext()
{
return false;
}
public object Current
{
get
{
return null;
}
}
}
class RealEnumberableClass : IEnumerable
{
public IEnumerator GetEnumerator()
{
throw new Exception("The method or operation is not implemented.");
}
}
Sunday, 8 July 2007
Model View Controller ?? Model View Presenter
Jean Paul Boodhoo explains what the Model View Presenter design pattern is and what's the difference between it and Model View Controller. I've never been a big fun of MVC because it tightly couples View and Model.
Great book: C# via CLR
As I mentioned earlier I always wanted to read C# via CLR by Jeffrey Richter. Finally I got it a few months ago and while I was sick I read it. I think it's just brilliant because:
- I like the way Jeffery explains problems.He is strict and precise whenever it's needed but no more.
- As far as I know he is not a Microsoft employee which lets him express criticism of everything that deserves it.
- It reveals lots of things that you will never be aware of unless you start thinking in an illogical way. Unfortunately CLR and/or C# not always behave in a predictable way.
- The books touches nearly all the .NET internals that you can come across during your everyday job as long as you don't work on compilers and runtimes :).
Thursday, 5 July 2007
You always struggle with formatting strings?
Check this out. It's a great crib sheet and I've even downloaded it to my machine. Just in case it disappears from the Internet :).
Tuesday, 26 June 2007
Silverlight is getting smaller and smaller...
The BCL team has announced that they've removed quite a few collections from the Silverlight version of the framework. It makes prefect sense to remove all non-generic classes but I can get why they've removed Stack<T> and Queue<T> as well. These 2 are very useful and people should not write them from scratch. That defeats the whole purpose of the .NET framework - leverage it. I don't know all the numbers but I can imagine it wouldn't harm Silverlight if they left them.
Wednesday, 20 June 2007
Friday, 1 June 2007
Irish Microsoft Technology Conference - go there to see people
Irish Microsoft Technology Conference is taking place next week. Though it's an overview what's out there in terms of Microsoft technology and thus there are not many sessions that explains things in depth it's worth going there. I can see really great speakers there that can reveal a few secrets having a pint with you :). I'm off to Spain for two weeks thus I will miss this conference.
Saturday, 26 May 2007
How to pollute C#
You can call me a purist but from my point of view the most valuable feature of C# is its consistency and explicitness. It seems that there are 2 teams at Microsoft that work on C#. One of them introduces great features like LINQ but the second one seems to support laziness of any kind and keeps introducing features that may(will) confuse software developers. Unfortunately it looks like the 'bad' team is not going to stop its activity. Their last idea which is called partial methods and is dedicated to code generator vendors smells like a C/C++ concept. Why? Because a partial method consist of method declaration(C++ header file) and method implementation(C++ cpp file). If you don't provide an implementation then the C# compiler will remove all calls to that method from your code! This means that your C# code that sits in a.cs file doesn't correspond to the C# code compiler sends to MSIL generator. Maybe it's me but I am not mad about at least half of the features Microsoft ships with Orcas(.NET 3.5).
Wednesday, 16 May 2007
64 bits doesn't come for free
Nothing comes for free. This is obvious but I still see a lot of people thinking that 64 bits architecture is going to solve all their performance problems which is not true. Maoni is explaining this in terms of .NET.
Subscribe to:
Posts (Atom)


