Some basic performance tuning techniques are shared below.
Minimize HTTP Requests:
Most of this time is tied up in downloading all the components in the page: images, style sheets, scripts, Flash, etc. Reducing the number of components in turn reduces the number of HTTP requests required to render the page. This is the key to faster pages.
To reduce the number HTTP requests, we can combine the scripts into a single script page and refer that script in the page.
Loading the scripts in parallel:
What we usually do is include script files as static links in head tag as shown below.
<head>
<script type="text/javascript" src="Scripts/JQueryUI/jquery-1.9.1.js "></script>
<script type="text/javascript" src="Scripts/JQueryUI/jquery-ui-1.10.1.js "></script>
</head>
What browsers usually do is download them serially one after the other. The browsers like IE or Firefox will wait for the first script to get downloaded before it starts downloading second one.
We can make them to download in parallel by the below code.
<script type="text/javascript">
document.writeln("<script src='Scripts/JQueryUI/jquery-1.9.1.js ?version=1.0
' type='text/javascript'><" +
"/script>");
document.writeln("<script src='Scripts/JQueryUI/jquery-ui-1.10.1.js ?version=1.0
' type='text/javascript'><" +
"/script>");
</script>
Avoiding the Cache Problem:
What most of the browsers do is that for the first time they download scripts to webpage but after that they take the script from the browser cache.so sometimes even if we make changes in the script and the style sheet ,that is not getting downloaded and changes are not reflecting.
We can force the browser to download the latest version of script and style sheet by versioning them.
<script type="text/javascript">
document.writeln("<script src='Scripts/JQueryUI/jquery-1.9.1.js ?version=1.0
' type='text/javascript'><" +
"/script>");
document.writeln("<script src='Scripts/JQueryUI/jquery-ui-1.10.1.js ?version=1.0
' type='text/javascript'><" +
"/script>");
</script>
<link href="Styles/includes.css?version=1.0" rel="stylesheet" type="text/css" />
We have to increment the version number if we make changes to that script or style sheet.
<script type="text/javascript">
document.writeln("<script src='Scripts/JQueryUI/jquery-1.9.1.js ?version=1.1
' type='text/javascript'><" +
"/script>");
document.writeln("<script src='Scripts/JQueryUI/jquery-ui-1.10.1.js ?version=1.1
' type='text/javascript'><" +
"/script>");
</script>
<link href="Styles/includes.css?version=1.1" rel="stylesheet" type="text/css" />
Bundling and Minification:
Bundling and Minification is the new feature included ASP.NET 4.5 to improve request load time.
To use Bundling and Minifcation, we have to add reference to System.Web.Optimization dll.
public class BundleConfig
{
// For more information on Bundling, visit http://go.microsoft.com/fwlink/?LinkId=254725
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jquery").Include(
"~/Scripts/jquery-1.7.min.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryui").Include(
"~/Scripts/jquery-ui-{version}.js"));
bundles.Add(new ScriptBundle("~/bundles/jqueryval").Include(
"~/Scripts/jquery.unobtrusive*",
"~/Scripts/jquery.validate*"));
}
}
The bundled scripts can be rendered by the following code in html page.
@System.Web.Optimization.Scripts.Render("~/bundles/modernizr")
@System.Web.Optimization.Scripts.Render("~/bundles/jquery")
SQL Server Parameter Sniffing:
Parameter sniffing allows you to reduce the time taken to execute the stored procedure considerably.
This permits individual plans recompilation instead of compiling entire execution plan for single store procedure. You could find below some workaround when you are affecting by a performance issue.
Using dummy variables that are not directly displayed on parameters also ensure execution plan stability without need to add recompile hint.
create procedure SearchProducts
@Keyword varchar(100)
As
Declare @Keyworddummy as varchar(100)
Set @Keyworddummy = @Keyword
select ProductID,ProductName from Products where Keyword like @Keyworddummy
end
Here the parameter @Keyword is assigned to @ Keyworddummy is which is used inside the stored procedure. Like this you can do for all the parameters that are used inside the stored procedure.
Always use the column name in the select list. Avoid using * in select.
This helps you to reduce the execution time considerably and get results faster.