<img height="1" width="1" style="display:none;" alt="" src="https://dc.ads.linkedin.com/collect/?pid=1005900&amp;fmt=gif">

Insights

Bad Code = Bad Performance Part 2

Part 2 – Server Side Code

This is part two of the blog discussing how bad code does often lead to bad performance of web pages, and what bad coding habits can contribute to the slow performance. In part one, I discussed how a lack of parallelism in code can slow performance down, and how using Parallel.ForEach loops could address this issue in given scenarios.

In this part of the blog, I shall be looking at Over-Reliance on Server-Side Code as a contributor to bad performance. Yet again, I shall be referring to and commentating on C# examples.

Discover how the Senior Delivery Manager at easyJet reduced risk through  capacity management in our on-demand webinar

 

Over-reliance on server side code

There is often too much reliance on server-side code to perform functions which would be capable of being completed on the client-side of the page. Let’s look at an example of a simple online registration form.

 

Bad code part 2

(Source: https://en-gb.facebook.com/)

 

A number of operations are generally executed when a user completes a form:

  1. User submits the form
  2. Validate that all form fields have been completed correctly
  3. If fields are fine, add new user to database
  4. Else, inform user that form fields are invalid
  5. Redirect user to different page, or return a message

If all of the functions for the operations above are executed server-side, the time taken to get from A to E is dependent largely on the performance of the server that the web site is hosted on.

Shifting some of these operations to client-side will reduce the load on the server, and will allow the capability of the browser to be utilised. The client-side code – which will most often be written in Javascript or jQuery – will be performed from the user’s browser, rather than from the site’s server, which reduces overhead and speeds the page up.

In this simple example, we could shift a large portion of the validation and message-returning onto client-side. We could even make use of AJAX to make a call to the server-side code to add the new user to the database.

bad code part 2 code

Admittedly, for security reasons, some checks and functions do have to be performed on the server side. However, where possible, client-side code operations reduces the demand put on the server, and reduces the number of calls and operations being made/performed on the server.

Less server reliance often equals faster performance.

Stay tuned for the third part of this blog, where I shall discuss how database queries can have a big impact on web page performance, when written and structured poorly.

 

Webinar easyJet reduce risk through capacity management