Showing posts with label optimization. Show all posts
Showing posts with label optimization. Show all posts

Monday, 3 June 2013

General - CSS JS Order Optimization

script.js
var i, total=0;
for (i=1;i<=3000;i++){
    total += Math.sqrt(2 * Math.pow(i, 2));;
    document.write("Total: " + total);
    document.write("<br>");
}
CSS then JS

JS then CSS

CSS, JS, CSS then JS

JS, CSS, JS then CSS

*In Most Cases, CSS FirstJS Second

More Info: 

Monday, 27 May 2013

Django - Select Related & Prefetch Related ORM Optimization


Initial
Sales.objects.filter(sales_person=self)

Select Related (O2O)
Sales.objects.select_related().filter(sales_person=self)

Prefetch Related (M2M / M2O)
Sales.objects.select_related().prefetch_related('booking_set', 'advancepayment_set', 'others_set').filter(sales_person=self)

More info:
https://docs.djangoproject.com/en/dev/ref/models/querysets/#select-related
https://docs.djangoproject.com/en/dev/ref/models/querysets/#prefetch-related

Django - Direct Foreign Key Optimization


No Query Execute
sales.customer_pk

Query Executed
sales.customer or sales.customer.pk

*Not working on Reverse Foreign Key, checking the instance properties by using dir(sales)

Source: https://docs.djangoproject.com/en/1.4/topics/db/optimization/#use-foreign-key-values-directly