SlideShare a Scribd company logo
SproutCore and
 Performance
“
    One should not pursue goals
    that are easily achieved. One
    must develop an instinct for
    what one can just barely
    achieve through one’s greatest
    efforts.


                     Albert Einstein
"Fast By
Default"
Core
Concepts
1. JS is
 cheaper
than DOM
2. Keep
Intermediate
 State in JS
(and out of
   DOM)
3. Events
 Cannot
Coalesce
(prefer
 cache
clearing)
4. Materialize
   Objects
 When Used
(also, proxy,
 don't copy)
5. Follow
 Speed
Guidelines
JS is
 Cheaper
than DOM
change name     change DOM

 change title    change DOM

change address   change DOM
change name

 change title    change DOM

change address
change name

 change title    change DOM

change address
SC
           run
          loop




browser
 event
  loop
handle event
native                    sync
         handle event
event                   bindings
         handle event
handle event
native                    sync
         handle event
event                   bindings
         handle event
handle event
native                    sync
         handle event
event                   bindings
         handle event
Event Handling

    JS Code

    JS Code

    JS Code

       ...

    DOM Code
Keep
Intermediate
 State in JS
Case Study
“   I want to have a view that
    displays the total number of
    items that are marked done.

    I want to have a feature that
    can mark all remaining items
    done.
What do you want to do?
4 items remaining


      Mark All Done

      Wash dishes
      Take out garbage
      Make bed
      Relax
What do you want to do?
4 items remaining


      Mark All Done

✓ Wash dishes
      Take out garbage
      Make bed
      Relax
What do you want to do?
3 items remaining


      Mark All Done

✓ Wash dishes
      Take out garbage
      Make bed
      Relax
What do you want to do?
3 items remaining


      Mark All Done

✓ Wash dishes
      Take out garbage
      Make bed
      Relax
What do you want to do?
3 items remaining


✓     Mark All Done

✓ Wash dishes
      Take out garbage
      Make bed
      Relax
What do you want to do?
0 items remaining


✓     Mark All Done

✓ Wash dishes
✓ Take out garbage
✓ Make bed
✓ Relax
"KVO"
item marked done



re-render stats view
Backbone
window.AppView = Backbone.View.extend({
  initialize: function() {
    _.bindAll(this, 'addOne', 'addAll', 'render');
    this.input    = this.$("#new-todo");
    Todos.bind('add',     this.addOne);
    Todos.bind('refresh', this.addAll);
    Todos.bind('all',     this.render);
    Todos.fetch();
  },
 
  render: function() {
    var done = Todos.done().length;
    this.$('#todo-stats').html(this.statsTemplate({
      total:      Todos.length,
      done:       Todos.done().length,
      remaining:  Todos.remaining().length
    }));
  }
});
Backbone


window.TodoList = Backbone.Collection.extend({
  done: function() {
    return this.filter(function(todo){
      return todo.get('done');
    });
  },
   
  remaining: function() {
    return this.without.apply(this, this.done());
  }
});
 
window.Todos = new TodoList;
Toggling




Todos.forEach(function(todo) {
  todo.toggle();
});
item marked done

compute remaining
                    xN
  compute done

render stats view
This is
foundational
No notion of
intermediate
    state
Prefer
Coalescing
Operations
SproutCore




ArrayController.create({
  content: [],

  remaining: function() {
    return this.filterProperty('isDone', false);
  }.property('@each.isDone')
});
Superficially
  Similar
intermediate state
 item marked done
                        xN
clear remaining cache

           run loop

 compute remaining

  render stats view
Easy to
Overlook
SproutCore




ArrayController.create({
  content: [],

  remaining: function() {
    return this.filterProperty('isDone', false);
  }.property('@each.isDone')
});
Key:
Declare
 Intent
"Coalesce"
Wrong
A         B

"hello"   "hello"
A     B

"1"   "1"
A      B

"12"   "12"
A       B

"123"   "123"
Right
A         B

"hello"   "hello"
A       B

"1"   "hello"
A       B

"12"   "hello"
A        B

"123"   "hello"
A                   B
        run loop
"123"              "hello"
A       B

"123"   "123"
Not 3
Deferred
Observers
Materialize
 Objects
When Used
Large JSON Structure




{
  contacts: [
    { name: "Yehuda", ... },
    ... x 10,000
  ]
}
Acre, Julie
Appleseed, Johnny
Arrow, Bob
Astels, David
Atwood, Michael
Axelrod, Peter
Azeroth, Roy
Contact
 Data Store     on demand   name
                            title
(JSON Hashes)               address
                            telephone
Ajax Response




                       RecordArray

 Data Store     live    Contacts
                       where
(JSON Hashes)          company =
                       "GOOGLE"
{
  Contact       name: "yehuda"
                title: "Chief Technologist"
data            address: "690 Spruce"
status          telephone: "718.877.1325"
            }
No Need to
  Copy
Properties
Again,
Foundational
One More
 Thing
Page Speed
Build Tools
Packed Files
CDN:
Versioned
  URLs
Expires
Header:
 Same
Stylesheets
 at the Top
Scripts at
the Bottom
Simple
Layout
External JS
 and CSS
Minification
Easier said
than done
SproutCore
    2.0
Matters, but not as much
as you think.




               Overall
              File Size
Modules w/
 Declared
  Deps
Lazy
Loading
Modules
Thank you.
Questions

More Related Content

PDF
Rails 3: Dashing to the Finish
PDF
jQuery in 15 minutes
PDF
Why You Shouldn't Write OO
PDF
jQuery and Rails, Sitting in a Tree
PPTX
jQuery Best Practice
PPT
PPT
JQuery introduction
PDF
Learning jQuery in 30 minutes
Rails 3: Dashing to the Finish
jQuery in 15 minutes
Why You Shouldn't Write OO
jQuery and Rails, Sitting in a Tree
jQuery Best Practice
JQuery introduction
Learning jQuery in 30 minutes

What's hot (20)

PDF
History of jQuery
PDF
Angular.js Fundamentals
PDF
Hack tutorial
PDF
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
PDF
Building Go Web Apps
PPTX
AngularJS Services
PPTX
AngularJS - $http & $resource Services
PDF
Drupal, meet Assetic
PPT
jQuery 1.7 Events
PDF
jQuery Loves Developers - Oredev 2009
PDF
How Kris Writes Symfony Apps
PPTX
Owl: The New Odoo UI Framework
PDF
Write Less Do More
PDF
Workshop 8: Templating: Handlebars, DustJS
PPTX
AngularJS Compile Process
PPTX
AngularJS Routing
PDF
Backbone.js — Introduction to client-side JavaScript MVC
PDF
Remy Sharp The DOM scripting toolkit jQuery
PDF
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
History of jQuery
Angular.js Fundamentals
Hack tutorial
Zepto.js, a jQuery-compatible mobile JavaScript framework in 2K
Building Go Web Apps
AngularJS Services
AngularJS - $http & $resource Services
Drupal, meet Assetic
jQuery 1.7 Events
jQuery Loves Developers - Oredev 2009
How Kris Writes Symfony Apps
Owl: The New Odoo UI Framework
Write Less Do More
Workshop 8: Templating: Handlebars, DustJS
AngularJS Compile Process
AngularJS Routing
Backbone.js — Introduction to client-side JavaScript MVC
Remy Sharp The DOM scripting toolkit jQuery
Meet Magento Sweden - Magento 2 Layout and Code Compilation for Performance
Ad

Viewers also liked (8)

PDF
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
PDF
Organizing jQuery Projects Without OO
PDF
Writing Fast Client-Side Code: Lessons Learned from SproutCore
PDF
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
PDF
Rails 3 overview
PDF
Making your oss project more like rails
PDF
Rails 3 Beautiful Code
KEY
Introducing PhoneGap to SproutCore 2
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Organizing jQuery Projects Without OO
Writing Fast Client-Side Code: Lessons Learned from SproutCore
Drupal + HTML5 + CSS3 + JS = Rich Internet Application
Rails 3 overview
Making your oss project more like rails
Rails 3 Beautiful Code
Introducing PhoneGap to SproutCore 2
Ad

Similar to Sprout core and performance (20)

PDF
mobl - model-driven engineering lecture
KEY
SproutCore is Awesome - HTML5 Summer DevFest
PDF
Viking academy backbone.js
PDF
Writing Maintainable JavaScript
PDF
Javascript MVC & Backbone Tips & Tricks
PDF
Backbone.js: Run your Application Inside The Browser
PPTX
Introduction to Knockoutjs
PDF
mobl presentation @ IHomer
PPTX
Taming that client side mess with Backbone.js
ODP
Javascript frameworks: Backbone.js
PDF
WebNet Conference 2012 - Designing complex applications using html5 and knock...
KEY
User Interface Development with jQuery
PPTX
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
PDF
Client-side MVC with Backbone.js (reloaded)
PDF
Client-side MVC with Backbone.js
PDF
PPTX
Maintainable JavaScript 2012
PDF
mobl
PPTX
Planbox Backbone MVC
PDF
Building a JavaScript Library
mobl - model-driven engineering lecture
SproutCore is Awesome - HTML5 Summer DevFest
Viking academy backbone.js
Writing Maintainable JavaScript
Javascript MVC & Backbone Tips & Tricks
Backbone.js: Run your Application Inside The Browser
Introduction to Knockoutjs
mobl presentation @ IHomer
Taming that client side mess with Backbone.js
Javascript frameworks: Backbone.js
WebNet Conference 2012 - Designing complex applications using html5 and knock...
User Interface Development with jQuery
Codemotion 2013 - Designing complex applications using html5 and knockoutjs
Client-side MVC with Backbone.js (reloaded)
Client-side MVC with Backbone.js
Maintainable JavaScript 2012
mobl
Planbox Backbone MVC
Building a JavaScript Library

More from Yehuda Katz (10)

PDF
SproutCore: Amber
PDF
Vaporware To Awesome
PDF
Merb Day Keynote
PDF
Testing Merb
PDF
Merb jQuery
PDF
Merb Camp Keynote
PDF
PDF
DataMapper
PDF
jQuery and Ruby Web Frameworks
PDF
jQuery Presentation to Rails Developers
SproutCore: Amber
Vaporware To Awesome
Merb Day Keynote
Testing Merb
Merb jQuery
Merb Camp Keynote
DataMapper
jQuery and Ruby Web Frameworks
jQuery Presentation to Rails Developers

Recently uploaded (20)

PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PDF
Unlocking AI with Model Context Protocol (MCP)
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Dropbox Q2 2025 Financial Results & Investor Presentation
PDF
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
PPT
Teaching material agriculture food technology
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
PDF
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
PDF
GamePlan Trading System Review: Professional Trader's Honest Take
PDF
Modernizing your data center with Dell and AMD
PDF
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
PPTX
20250228 LYD VKU AI Blended-Learning.pptx
PDF
Chapter 3 Spatial Domain Image Processing.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
PDF
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
PDF
The Rise and Fall of 3GPP – Time for a Sabbatical?
PDF
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Unlocking AI with Model Context Protocol (MCP)
Review of recent advances in non-invasive hemoglobin estimation
Dropbox Q2 2025 Financial Results & Investor Presentation
Peak of Data & AI Encore- AI for Metadata and Smarter Workflows
Teaching material agriculture food technology
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
Optimiser vos workloads AI/ML sur Amazon EC2 et AWS Graviton
GamePlan Trading System Review: Professional Trader's Honest Take
Modernizing your data center with Dell and AMD
7 ChatGPT Prompts to Help You Define Your Ideal Customer Profile.pdf
20250228 LYD VKU AI Blended-Learning.pptx
Chapter 3 Spatial Domain Image Processing.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
Shreyas Phanse Resume: Experienced Backend Engineer | Java • Spring Boot • Ka...
solutions_manual_-_materials___processing_in_manufacturing__demargo_.pdf
The Rise and Fall of 3GPP – Time for a Sabbatical?
Build a system with the filesystem maintained by OSTree @ COSCUP 2025
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...

Sprout core and performance

Editor's Notes