Search icon CANCEL
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
MASTERING KNOCKOUTJS

You're reading from   MASTERING KNOCKOUTJS Use and extend Knockout to deliver feature-rich, modern web applications

Arrow left icon
Product type Paperback
Published in Nov 2014
Publisher
ISBN-13 9781783981007
Length 270 pages
Edition 1st Edition
Arrow right icon
Author (1):
Arrow left icon
Timothy Moran Timothy Moran
Author Profile Icon Timothy Moran
Timothy Moran
Arrow right icon
View More author details
Toc

Table of Contents (11) Chapters Close

Preface 1. Knockout Essentials 2. Extending Knockout with Custom Binding Handlers FREE CHAPTER 3. Extending Knockout with Preprocessors and Providers 4. Application Development with Components and Modules 5. Durandal – the Knockout Framework 6. Advanced Durandal 7. Best Practices 8. Plugins and Other Knockout Libraries 9. Under the Hood Index

Performance concerns


Knockout's performance has improved several times since its initial release, but it is still possible to encounter issues in apps with a large number of operations or objects. While some decrease in performance should be expected as the work being done increases, there are ways to ease the burden on the CPU.

Observable loops

Changing observable arrays inside loops causes them to publish change notifications multiple times. The cost of these changes is proportional to the size of the array. You might need to add several items to an array and use a loop to do this:

var contacts = ko.observableArray();
for (var i = 0, j = newContacts.length; i < j; i++) {
    contacts.push(new Contact(newContacts[i]);
}

The problem here is that push gets called multiple times, which causes the array to send out multiple change notifications. It's much easier for the subscribers of the array if all of the changes are sent at once. This can be done by collecting all of the changes in the loop...

lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $19.99/month. Cancel anytime