C# Question

Does lessening lines of code decrease load time of a project?

I have a .NET solution which contains multiple projects with in it.

Have identified some potential hot spots of the project which can be improved.

E.g. Considering a ternary operator wherever it is possible.

The question is this:

  1. Is this worth the effort ? Going through all the projects and lessening lines of code improves something apart from code beautification ?

  2. Are there any standard ways / standard steps that can be followed to improve the code base (performance/loading time/etc.,) ?

Asking this with respect to Visual studio 2015 & .NET realms.

Answer Source

Replacing if statements with an equivalent ternary operator will usually have no impact whatsoever on the generated code. The compiler is quite good at optimizing these things to the exact same sequence of instructions regardless of how you write them at a high level.

Generally, dumb reduction of the number of lines of code without any actual restructuring of the code will not have any effect on the size of the project.

Restructuring the code may have an effect, but unless you have really stupid things going on, like completely unused or completely useless code, you have to be smart in how you restructure things, and it requires a lot of work.

Usually, performance and loading time improvements require more code, not fewer code. For example, if you are hitting a certain repository a lot during startup, and this slows you down, then what will make your program load faster is the introduction of a caching mechanism that reduces the number of hits to the repository. This caching mechanism will need to be added, so that will be more code.

Getting rid of unused libraries, configuring libraries to do less during startup, replacing libraries with just a couple of functions if that's all the functionality you use for them, is usually the lowest hanging fruit.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download