Sunday, November 23, 2008

Tips and Tricks of Dotnet

If you are implementing atleast 10 of the below tricks / tips in your code, you are giving performance oriented to your client. This is a collection from my previous experience or my reading on internet.

System.io.compression namespace has the objects useful for zipping and unzipping files in .net 2.0 onwards. Sharpzip is also a opensource option.

To remove the dupliacates in an arraylist simply copy it into hashset (hashes eliminate duplicates) and copy that back into arraylist.

Databinder.eval has same syntax for vb.net and c#.net, it might be a performance block because it uses runtime reflection to convert the object (int,object,byte,string) into a string. Better use Databinder.datarow[i]......

using the WebRequest class, you can screen scrape web pages, and pass the resulting Html string to the MailMessage object. Mail will look like your html page.

How many TPS (Transactions Per Second) you want to your application to handle.

Perfromance Objectives are Throughput, Response time, Resource utilization, work load (data , users, transactions)

Coupling cohesion, communication, concurrency, resource, caching, state management, Datastructures and algorithms.

If your image has fewere colors use GIF format, if your image has more colors use JPEG.

Arraylist, sortedlist, Namedvalue collection --->sort

Hashtable, stringdictionary, listdictionary ---> search

Don't use Array list for storing strings, use it for custom objects and where you have insert and delete operations frequently.

use string collection to store strings. Use hash table for frequently queried data, with key pair combination. Use hybrid Dictionary for frequently queried data , low size.

use queue for FIFO kind of purposes and stack for LIFO kind of purposes. Use Sorted list for fast object retrieval (don't use it for large amount of data). In case of large data use array list and use sort method.

Hybrid Dictionary uses List dictionary for small size data and uses hash table for large data. List dictionary is useful for 10 or less key value players.

Use for loop instead of Foreach , because of enumeration in foreach loop performance will be hit.

StringCollection is strongly typed arraylist of strings.

StringDictionary is a hash table with the key strongly typed to be a string rather than an object.

Early binding allows the compiler to identify the specific type required and perform optimizations that
are used at run time. Late binding defers the type identification process until run time and requires
extra processing instructions to allow type identification and initialization. (TypeOf, GetType, and IsInstanceOfType)

each time you are using string concatination, new string is created. so use string builder instead of string if you want to do concatination.

always use page.ispostback == false for first time initializations

Use server.transfer than response.redirect, ensure debug is set to false, clientside validations

Don't mix multiple languages in the same directory.

pages having server control, datagrid will increase load of viewstate. Avoid server controls when not needed, like no need to retain across postbacks (labels), readonly data.

Use caching on asp.net page, it uses LRU(least recently used) algo to clear the content. you can expire the cache with timer also. put infrequently modified data like headers in cache.

If you want to store user specific data use session instead of caching.

Use cookies, hiddencontrol, querystring for lightweight data and not needed much security.

Response.write, string builder, htmltextwriter are good for performance.

From asp.net 2.0 onwards you can take advantage of 64 bit servers.

use System.data.sqlclient for sql 7.0 onwards (as it uses TDS - Tabular Data Stream protocol). System.data.oledb for sqlserver 6.5

when using datareader specify commandbehaviour.close connection.

use executenonquery for commands that doesnt return any data. dont use select *, specify columns you need. Set NO COUNT ON in stored proc.

2 comments:

  1. Dear Surya,
    I guess you meant the opposite when you said "Use queue for LIFO kind of purposes and stack for FIFO kind of purposes"... Don't you think?

    ReplyDelete
  2. Surya,
    After reading it all... I must say this "THANKS" :)

    ReplyDelete

 
web counter
Download a free hit counter here.