Tuesday, June 01, 2010

Measuring performance: Dictionary Vs If Else

Mark Needham from Thought Works has recently blogged about using Dictionary instead of If Else statements. The usage of If Else is very common in similar situations however as number of scenarios grow things can become night mare. And at some point of time you have to think about some smart approach such as the one mentioned by Mark.

At first, I thought making entire logic dictionary based may impact performance because of key lookup calls. And that motivated me to write a sample script to verify my understanding. Along with the two approaches, I was also interested to know performance implications using Switch statement. For such quick performance tests, I really love playing with
Stopwatch class.

I run the test 1k times and am very happy with the results I got. Along with better readability and maintainability, you get little bit of performance improvement as well. It’s win-win from all the sides. Such tests may seem trivial but it implant solid craftsmanship towards clean code.

Results (in ms):
Using If Else > 1130
Using Switch > 1057
Using Dictionary > 1062


Thursday, May 20, 2010

Smart Data Transfer Object

Too often it happens when you work on distributed application that you communicate too many times to fulfill a single request. As in any network communication actual data transfer (serialization, compression, transfer over wire, decompression, deserialization, etc) is just one part and other network protocol activities also expense you nicely. You always want to minimize number of calls to the server by fetching all data that you require at once and in result better overall responsiveness.

In one of the web project, we had to present navigation tree on the left side. The tree nodes were populated based on authorization and node attributes such as Hidden, etc. Initially, when we started with implementation we simply fetched nodes using SELECT N+1 method. That was easy and simple. But as no. of nodes got increased, we started experiencing delayed response.

So then we come across
DTO pattern and using my own efficient n-level hierarchy traversal method we fetched all tree nodes at once to be sent to the client. But then this approach has contradicted with Split the initial payload guideline (its written for web UI for good for any presentation layer) and lazy loading (loading only if required).

As to solve second round of problem, we limited traversal depth level to 3. That not just reduced number of calls to server (and conforming with DTO) but also increased initial response. At max, however it is not limited, we had depth level of 5 so once the application is loaded client only had to make two more calls to reach to the node at fifth level. Well, I think that is acceptable.

To further optimize, may be we can think of expanding entire sub-tree when client explicitly ask to drill down for a given node. It just works for us and thought to share with you.


Monday, May 10, 2010

Do you buy Abstraction?

If your answer is NO, go and read below paragraph from The Gu. He answered people questioning ASP.NET MVC on the ground of abstraction. Check his complete post.

I always find it somewhat ironic when I hear people complain about programming abstractions not being good. Especially when these complaints are published via blogs – whose content is displayed using HTML, is styled with CSS, made interactive with JavaScript, transported over the wire using HTTP, and implemented on the server with apps written in higher-level languages, using object oriented garbage collected frameworks, running on top of either interpreted or JIT-compiled byte code runtimes, and which ultimately store the blog content and comments in relational databases ultimately accessed via SQL query strings. All of this running within a VM on a hosted server – with the OS within the VM partitioning memory across kernel and user mode process boundaries, scheduling work using threads, raising device events using signals, and using an abstract storage API fo disk persistence. It is worth keeping all of that in mind the next time you are reading a “ORM vs Stored Procedures” or “server controls – good/bad?” post. The more interesting debates are about what the best abstractions are for a particular problem.


Thursday, February 04, 2010

SQL Object Search made easy!

Ever since I developed DB Search Util back in 2006, it has made my life lot easier. I was trying to find a string instance in different tables and was literally clueless. Out of frustration for those two days, I decided to play with SQL system tables and figured out how tables and their schemas are stored. Next thing was quite simple as I just had to query the table to see if particular string instance exist in the row set or not. Obviously there were technical challenges but were trivial, to be honest.

Since then this tiny utility become popular among Altiris (now Symantec) people at Cybage and there is nothing more satisfying to know that the utility is being introduced in SMP sessions for new comers.

Even though, I am consciously aware about weaknesses of the tool, I have never stretched myself to developed those extra bits. Biggest among them is an ability to search for SQL Object names itself rather than data. I don’t know if I would do that but recent announcement from red-gate has filled the gap. Give it a try and please yourself when you try to find objects out of 500+.


Note: For legal purposes I can’t show code snippet of the DB Search Util. However the first paragraph is enough and won’t take more than 6 hours to develop.


Wednesday, September 23, 2009

Are you worried over cross IE browser support?

If you are migrating your web application developed for IE6/IE7 to IE8, you know involved pain as much as I do. There are lot of things you have to tweak – and the list is not limited to CSS, JS or DOM. In a recent development where in my job was to support IE8 in native mode without breaking IE7 – I was heavily dependent on IETester. However that is more helpful towards rendering, CSS and DOM. So, as to get final picture I managed multiple VMs running different flavors of machines combining operating systems and browsers. This is again not so easy and full of hurdles.

Finally, today I noticed Microsoft announcement on Microsoft Expression Web SuperPreview. I have just downloaded it and checking how much it would be helpful. This tool announcement makes more sense to me because it’s from IE manufacturer – Microsoft.


Wednesday, September 09, 2009

Make sure to check DOLOTO against your web 2.0 sites

DOLOTO was been eagerly awaited by community for more than a year. The technique to optimize AJAX based applications named - Spitting the initial payload interested many but there was no formal tool to automate that. And most of the time people have to do that manually.

DOLOTO is brain child of Microsoft Research and more information along with installer can be found at below location. The idea is still fresh and you may want to share your results to “dolotofb at microsoft dot com”.

DOLOTO: Download time optimizer for Web 2.0 apps


Friday, July 10, 2009

Are you jing?

One of the most wonderful free tool I have ever come across – “the Jing”. Capture, Save & Share is what the mantra of Jing team. I am listing few important features that would interest you.

Jing Screen capture:
  • Capture screens and decorate it in one go.
  • Very rich image edit tool will allow you to put text, arrows, boxes, etc.
  • The editing tool is far better than any other including MS paint and it has just required things.
Jing Video capture:
  • Capture screen happening as much as you want
  • Save the entire video and share with your colleagues
  • It saves in SWF format so that you can view the video on any machine.
I would recommend this tool to any QA and Dev who want to communicate anything visually. Many a times, Dev complain about exact steps for any defect reproduction and then QA carry them to their desk to show the steps. This tool can capture your steps so that you the QA or Dev just have to send the SWF and you are done.

I played with the tool for some time today and found that it has all the power to put you in a great comfort. Check the below link.