SlideShare une entreprise Scribd logo
1  sur  51
Télécharger pour lire hors ligne
Who are these dudes?
suprememoocow
mydigitalself
Andrew Newdigate
Mike Bartlett
Gitter is where
developers come to talk
120 000 registered users
24 000 public communities
Active every minute of every day
502 releases in 1.5 years
Zawinksi’s Law
Every program attempts to expand until it can read mail.
Those programs which cannot so expand are replaced by ones which can.
Act 1
Performance
Global Average
4.5Mbps
Akamai
Two Great Tools
OSX Network Link Conditioner
Chrome DevTools Network Throttle
Scene 1
Mistake: Assuming jQuery is fast enough
Chuck Norris’ keyboard
Finding performance problems
Don’t optimise too early
Focus on CollectionViews, CompositeViews
Improving the performance 1000% on a view that gets rendered once in
the application isn’t going to make the slightest bit of difference.
The Chrome
DevTools
Timeline is
Awesome
Example of
using Timelines
$.tooltip is really slow
Solution: change the tooltip
behaviour to only initialise the
tooltip on the first mouseover event
fired on the element
1ms per tooltip to 0.005ms per
tooltip
Easy performance win: attachElContent
Override this method in your collection/composite child views
// Abbreviated version of the attachElContent MixIn we use on Gitter
attachElContent: function(html) {
if (typeof html === 'string') {
this.el.innerHTML = html;
return this;
}
this.$el.html(html);
return this;
}
.innerHTML vs $.html
Scene 2
Mistake: Not pre-rendering content
Pre-rendering is good practice
Page indexing / SEO advantages to doing it
Perceived speed of page load is much faster
Avoid multiple reflows as the application loads
Less jankiness
Pre-rendering is messy
At the moment, done through a series of hacks:
• Server-side handlebars helpers
• Client-side Marionette extensions
Would be awesome to move this out into a semi-sane, open-source
library (or build it into Marionette!)
Fully pre-rendered Partially pre-rendered
Isomorphic LayoutViews
In LayoutView’s before:show event
• If the region is empty, initialise ChildView as per normal:
• If the region already contains content, mount the ChildView on the
existing element: 



view.showChildView(regionName,
new ChildView({ el: existingElement, template: false, ... options ... }));
view.showChildView(regionName, new ChildView({ ... options ... }));
Isomorphic CollectionViews
childViewOptions: function (model) {
if (!model.id) return;
var el = this.$el.find('> [data-id="' + model.id + '"]')[0];
if (!el) return;
return {
el: el,
template: false
};
},
<ul>
<li data-id="1">One</li>
<li data-id="2">Two</li>
<li data-id="3">Three</li>
</ul>
collection.reset([
{ id: “1”, name: “One” },
{ id: “2”, name: “Two” },
{ id: “3”, name: “Three” }
]);
Scene 3
Mistake: Too much Jason
“640 people ought to be enough for any room”
Thanks!
People Roster Data
~300 characters
In a 5000 user room, that’s 1.4MB of JSON
Retina and non-retina avatar URLs
Unused fields, duplicate data, etc
{
"id": "5298e2d5ed5ab0b3bf04c980",
"username": "suprememoocow",
"displayName": "Andrew Newdigate",
"url": "/suprememoocow",
"avatarUrlSmall": "https://avatars1.githubuser
"avatarUrlMedium": "https://avatars1.githubuse
"gv": "3",
"v": 30
}
How we represent them now
77 characters
In a 5000 user room, that’s still 375KB.
Limit the list to the first 20 people
{
"id": "5298e2d5ed5ab0b3bf04c980",
"username": "suprememoocow",
"gv": "3",
"v": 30
}
Scene 4
Mistake: Using .on too much
.on is a code smell
Using jquery events
Backbone events
Also, beware of long running setTimeouts
this.ui.actionButton.on('click', function() { 

window.alert('Yo'); 

});
this.model.on('change', function() { 

window.alert('Yo'); 

});
Obvious solution
Use modelEvents, collectionEvents and events
modelEvents: {
'change': 'onChange'
},
events: {
'click @ui.badge': 'onBadgeClicked'
},
collectionEvents: {
'add reset sync reset': 'showHideHeader'
},
Use listenTo for listening to Backbone.Events
this.listenTo(model, 'change', function() { })
When you still need .on
Remember to cleanup after yourself
onClick: function() {
this.$someElement.on('mouseenter', ...);
this.longRunningTimer = setTimeout(function() {}, 60000);
},
onDestroy: function() {
this.$someElement.off();
clearTimeout(this.longRunningTimer);
},
DevTools Heap
Snapshots
Take periodic snapshots
and use the comparison
view to find new allocations
Act 2
Software design mistakes
Scene 1
Mistake: Coupling view components together
MV* 101
This is how we’re taught to
structure MV* applications
at school.
Sometimes it’s easier to ignore the advice
We need to tell another view to do
something.
We’re in a rush, so we’ll just wire the
dependency in and fix it later.
var MyView = Mn.ItemView.extend({
...
onActionClicked: function() {
this.options.anotherView.doSomething();
},
})
var myView = new MyView({ anotherView:
anotherView });
Pretty soon we’ve got a tightly coupled mess
This makes change hard
Just try to:
• Move a view within the view hierarchy
• Remove a view in a certain environment
(unauthenticated view, mobile, etc)
Let’s change things
around a bit…
Marionette solutions
Use a shared model and update the model
wreqr, or better yet, Backbone.Radio
Imaginary Radio Behaviour
var MyView = Mn.ItemView.extend({
behaviors: {
Radio: {
name: 'ui',
comply: {
'chat:focus': 'focusChat'
…
},
focusChat: function() {
// ....
}
});
var AnotherView = Mn.ItemView.extend({
behaviors: {
Radio: {
name: 'ui'
},
},
onActionClicked: function() {
this.radio.command('chat:focus');
}
});
*correct spelling
Scene 2
Mistake: Messing with another view’s DOM
Quick and dirty
A component needs to respond to an action and change another
component’s DOM…
Easiest solution: just use jquery
onClick: function() {
$('#action-button').hide();
}
c/c++ pointer arithmetic
In c/c++, it’s possible to use pointer arithmetic to directly modify the
contents of a location in memory.
I’m sure you will all agree: this is a VERY BAD IDEA!
bptr = (byte*) &data;
bptr = bptr + 5;
iptr = (int*) bptr;
(*iptr) = 0xcafebabe;
Now imagine…
Your DOM is a global memory shared by all the Javascript code running
in your app
Each view in your app manages a distinct piece of the global memory
Mutating another view’s DOM is a bit like using pointer arithmetic to
change it’s memory behind it’s back
Don’t do it!
But why?
Refactoring becomes a nightmare
You’re creating hidden connections between views in your application.
Scene 3
Mistake: Different module formats on the client and server
Then
Client: AMD modules with RequireJS
Tests: run in a phantomjs
Server: commonjs modules with nodejs
Tests run in nodejs with mocha
Now
Client: commonjs modules with webpack
Server: commonjs modules with nodejs
Shared code is kept in shared
Shared code can be tested quickly using the nodejs and mocha, without
having to start a phantomjs browser
require.ensure();
// In your backbone router....
markdown: function() {
require.ensure(['views/markdown/markdownView'], function(require) {
var MarkdownView = require('views/markdown/markdownView');
appView.dialogRegion.show(new MarkdownView({}));
});
},
Act 3
In closing
Code Debt
A lot of these problems as the result of technical debt. When we started
building the project we chose Backbone, and only later did we switch to
Marionette.
Initially, we treated Marionette as a neat extension of Backbone, for
things like CollectionViews etc so the transition was gradual and left a
lot of technical debt around.
Marionette 2 PR
From a small prototype to a large application
A lot of the pain we’ve experienced has been down to the fact that we
started off with a small application which has grown larger and larger.
Start as you mean to go on
Gitter marionette deck

Contenu connexe

Tendances

Marionette: Building your first app
Marionette: Building your first appMarionette: Building your first app
Marionette: Building your first appfrontendne
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface ComponentsAhmad Hamid
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript DevelopmentAddy Osmani
 
Building Large Scale Javascript Application
Building Large Scale Javascript ApplicationBuilding Large Scale Javascript Application
Building Large Scale Javascript ApplicationAnis Ahmad
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture Jiby John
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developersKai Koenig
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaEdureka!
 
Five class-based views everyone has written by now
Five class-based views everyone has written by nowFive class-based views everyone has written by now
Five class-based views everyone has written by nowJames Aylett
 
React - An Introduction
React - An IntroductionReact - An Introduction
React - An IntroductionTyler Johnston
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todaygerbille
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiJared Faris
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Gabor Varadi
 
Dom selecting & jQuery
Dom selecting & jQueryDom selecting & jQuery
Dom selecting & jQueryKim Hunmin
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & AngularAlexe Bogdan
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponentsMartin Hochel
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"GeeksLab Odessa
 

Tendances (20)

Marionette: Building your first app
Marionette: Building your first appMarionette: Building your first app
Marionette: Building your first app
 
Flex Building User Interface Components
Flex Building User Interface ComponentsFlex Building User Interface Components
Flex Building User Interface Components
 
Large-Scale JavaScript Development
Large-Scale JavaScript DevelopmentLarge-Scale JavaScript Development
Large-Scale JavaScript Development
 
Building Large Scale Javascript Application
Building Large Scale Javascript ApplicationBuilding Large Scale Javascript Application
Building Large Scale Javascript Application
 
jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture jQquerysummit - Large-scale JavaScript Application Architecture
jQquerysummit - Large-scale JavaScript Application Architecture
 
AngularJS for designers and developers
AngularJS for designers and developersAngularJS for designers and developers
AngularJS for designers and developers
 
Top 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | EdurekaTop 45 jQuery Interview Questions and Answers | Edureka
Top 45 jQuery Interview Questions and Answers | Edureka
 
Five class-based views everyone has written by now
Five class-based views everyone has written by nowFive class-based views everyone has written by now
Five class-based views everyone has written by now
 
AngularJs
AngularJsAngularJs
AngularJs
 
Android how to hellowidget
Android how to hellowidgetAndroid how to hellowidget
Android how to hellowidget
 
React - An Introduction
React - An IntroductionReact - An Introduction
React - An Introduction
 
Creating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of todayCreating the interfaces of the future with the APIs of today
Creating the interfaces of the future with the APIs of today
 
Building Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript SpaghettiBuilding Rich User Experiences Without JavaScript Spaghetti
Building Rich User Experiences Without JavaScript Spaghetti
 
Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)Architecting Single Activity Applications (With or Without Fragments)
Architecting Single Activity Applications (With or Without Fragments)
 
Dom selecting & jQuery
Dom selecting & jQueryDom selecting & jQuery
Dom selecting & jQuery
 
The AngularJS way
The AngularJS wayThe AngularJS way
The AngularJS way
 
5 angularjs features
5 angularjs features5 angularjs features
5 angularjs features
 
Client Side MVC & Angular
Client Side MVC & AngularClient Side MVC & Angular
Client Side MVC & Angular
 
Reactive Type-safe WebComponents
Reactive Type-safe WebComponentsReactive Type-safe WebComponents
Reactive Type-safe WebComponents
 
JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"JSLab. Алексей Волков. "React на практике"
JSLab. Алексей Волков. "React на практике"
 

En vedette

Attachment
AttachmentAttachment
Attachmentwhatmwwt
 
Attachment final
Attachment finalAttachment final
Attachment finalwhatmwwt
 
Desarrollo organisacional
Desarrollo organisacional Desarrollo organisacional
Desarrollo organisacional Juan Vilela
 
Ada lovelace expocicion
Ada lovelace expocicionAda lovelace expocicion
Ada lovelace expocicionJanina Sanchez
 
Teaching science through games
Teaching science through gamesTeaching science through games
Teaching science through gamesgayukana
 

En vedette (8)

English
EnglishEnglish
English
 
Attachment
AttachmentAttachment
Attachment
 
Before & After Walls Design
Before & After Walls DesignBefore & After Walls Design
Before & After Walls Design
 
How to choose a contractor
How to choose a contractorHow to choose a contractor
How to choose a contractor
 
Attachment final
Attachment finalAttachment final
Attachment final
 
Desarrollo organisacional
Desarrollo organisacional Desarrollo organisacional
Desarrollo organisacional
 
Ada lovelace expocicion
Ada lovelace expocicionAda lovelace expocicion
Ada lovelace expocicion
 
Teaching science through games
Teaching science through gamesTeaching science through games
Teaching science through games
 

Similaire à Gitter marionette deck

jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applicationsDivyanshGupta922023
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with ReduxFITC
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applicationsMilan Korsos
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsclimboid
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistMark Fayngersh
 
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaAdvanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaXamarin
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applicationsIvano Malavolta
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteRavi Bhadauria
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Previewvaluebound
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptjasonsich
 
Zend server 6 using zf2, 2013 webinar
Zend server 6 using zf2, 2013 webinarZend server 6 using zf2, 2013 webinar
Zend server 6 using zf2, 2013 webinarYonni Mendes
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reactionjbandi
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBoyan Mihaylov
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework ReactionJonas Bandi
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinBarry Gervin
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsJeff Durta
 

Similaire à Gitter marionette deck (20)

jquery summit presentation for large scale javascript applications
jquery summit  presentation for large scale javascript applicationsjquery summit  presentation for large scale javascript applications
jquery summit presentation for large scale javascript applications
 
Building React Applications with Redux
Building React Applications with ReduxBuilding React Applications with Redux
Building React Applications with Redux
 
Developing large scale JavaScript applications
Developing large scale JavaScript applicationsDeveloping large scale JavaScript applications
Developing large scale JavaScript applications
 
Yeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web appsYeoman AngularJS and D3 - A solid stack for web apps
Yeoman AngularJS and D3 - A solid stack for web apps
 
The State of Front-end At CrowdTwist
The State of Front-end At CrowdTwistThe State of Front-end At CrowdTwist
The State of Front-end At CrowdTwist
 
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo KumperaAdvanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
Advanced Memory Management on iOS and Android - Mark Probst and Rodrigo Kumpera
 
Fundaments of Knockout js
Fundaments of Knockout jsFundaments of Knockout js
Fundaments of Knockout js
 
Mobile optimization
Mobile optimizationMobile optimization
Mobile optimization
 
Vanjs backbone-powerpoint
Vanjs backbone-powerpointVanjs backbone-powerpoint
Vanjs backbone-powerpoint
 
Developing maintainable Cordova applications
Developing maintainable Cordova applicationsDeveloping maintainable Cordova applications
Developing maintainable Cordova applications
 
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia InstituteMVC Design Pattern in JavaScript by ADMEC Multimedia Institute
MVC Design Pattern in JavaScript by ADMEC Multimedia Institute
 
React JS: A Secret Preview
React JS: A Secret PreviewReact JS: A Secret Preview
React JS: A Secret Preview
 
Intro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScriptIntro to React - Featuring Modern JavaScript
Intro to React - Featuring Modern JavaScript
 
Zend server 6 using zf2, 2013 webinar
Zend server 6 using zf2, 2013 webinarZend server 6 using zf2, 2013 webinar
Zend server 6 using zf2, 2013 webinar
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
Bringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJSBringing the light to the client with KnockoutJS
Bringing the light to the client with KnockoutJS
 
From User Action to Framework Reaction
From User Action to Framework ReactionFrom User Action to Framework Reaction
From User Action to Framework Reaction
 
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry GervinWill your code blend? : Toronto Code Camp 2010 : Barry Gervin
Will your code blend? : Toronto Code Camp 2010 : Barry Gervin
 
Building richwebapplicationsusingasp
Building richwebapplicationsusingaspBuilding richwebapplicationsusingasp
Building richwebapplicationsusingasp
 
Adding a modern twist to legacy web applications
Adding a modern twist to legacy web applicationsAdding a modern twist to legacy web applications
Adding a modern twist to legacy web applications
 

Dernier

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Allon Mureinik
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptxLBM Solutions
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 

Dernier (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)Injustice - Developers Among Us (SciFiDevCon 2024)
Injustice - Developers Among Us (SciFiDevCon 2024)
 
Key Features Of Token Development (1).pptx
Key  Features Of Token  Development (1).pptxKey  Features Of Token  Development (1).pptx
Key Features Of Token Development (1).pptx
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 

Gitter marionette deck

  • 1.
  • 2. Who are these dudes? suprememoocow mydigitalself Andrew Newdigate Mike Bartlett
  • 3. Gitter is where developers come to talk 120 000 registered users 24 000 public communities Active every minute of every day 502 releases in 1.5 years
  • 4. Zawinksi’s Law Every program attempts to expand until it can read mail. Those programs which cannot so expand are replaced by ones which can.
  • 7. Two Great Tools OSX Network Link Conditioner Chrome DevTools Network Throttle
  • 8. Scene 1 Mistake: Assuming jQuery is fast enough
  • 10. Finding performance problems Don’t optimise too early Focus on CollectionViews, CompositeViews Improving the performance 1000% on a view that gets rendered once in the application isn’t going to make the slightest bit of difference.
  • 12. Example of using Timelines $.tooltip is really slow Solution: change the tooltip behaviour to only initialise the tooltip on the first mouseover event fired on the element 1ms per tooltip to 0.005ms per tooltip
  • 13. Easy performance win: attachElContent Override this method in your collection/composite child views // Abbreviated version of the attachElContent MixIn we use on Gitter attachElContent: function(html) { if (typeof html === 'string') { this.el.innerHTML = html; return this; } this.$el.html(html); return this; }
  • 15. Scene 2 Mistake: Not pre-rendering content
  • 16. Pre-rendering is good practice Page indexing / SEO advantages to doing it Perceived speed of page load is much faster Avoid multiple reflows as the application loads Less jankiness
  • 17. Pre-rendering is messy At the moment, done through a series of hacks: • Server-side handlebars helpers • Client-side Marionette extensions Would be awesome to move this out into a semi-sane, open-source library (or build it into Marionette!)
  • 19. Isomorphic LayoutViews In LayoutView’s before:show event • If the region is empty, initialise ChildView as per normal: • If the region already contains content, mount the ChildView on the existing element: 
 
 view.showChildView(regionName, new ChildView({ el: existingElement, template: false, ... options ... })); view.showChildView(regionName, new ChildView({ ... options ... }));
  • 20. Isomorphic CollectionViews childViewOptions: function (model) { if (!model.id) return; var el = this.$el.find('> [data-id="' + model.id + '"]')[0]; if (!el) return; return { el: el, template: false }; }, <ul> <li data-id="1">One</li> <li data-id="2">Two</li> <li data-id="3">Three</li> </ul> collection.reset([ { id: “1”, name: “One” }, { id: “2”, name: “Two” }, { id: “3”, name: “Three” } ]);
  • 21. Scene 3 Mistake: Too much Jason
  • 22. “640 people ought to be enough for any room”
  • 24. People Roster Data ~300 characters In a 5000 user room, that’s 1.4MB of JSON Retina and non-retina avatar URLs Unused fields, duplicate data, etc { "id": "5298e2d5ed5ab0b3bf04c980", "username": "suprememoocow", "displayName": "Andrew Newdigate", "url": "/suprememoocow", "avatarUrlSmall": "https://avatars1.githubuser "avatarUrlMedium": "https://avatars1.githubuse "gv": "3", "v": 30 }
  • 25. How we represent them now 77 characters In a 5000 user room, that’s still 375KB. Limit the list to the first 20 people { "id": "5298e2d5ed5ab0b3bf04c980", "username": "suprememoocow", "gv": "3", "v": 30 }
  • 26. Scene 4 Mistake: Using .on too much
  • 27. .on is a code smell Using jquery events Backbone events Also, beware of long running setTimeouts this.ui.actionButton.on('click', function() { 
 window.alert('Yo'); 
 }); this.model.on('change', function() { 
 window.alert('Yo'); 
 });
  • 28. Obvious solution Use modelEvents, collectionEvents and events modelEvents: { 'change': 'onChange' }, events: { 'click @ui.badge': 'onBadgeClicked' }, collectionEvents: { 'add reset sync reset': 'showHideHeader' }, Use listenTo for listening to Backbone.Events this.listenTo(model, 'change', function() { })
  • 29. When you still need .on Remember to cleanup after yourself onClick: function() { this.$someElement.on('mouseenter', ...); this.longRunningTimer = setTimeout(function() {}, 60000); }, onDestroy: function() { this.$someElement.off(); clearTimeout(this.longRunningTimer); },
  • 30. DevTools Heap Snapshots Take periodic snapshots and use the comparison view to find new allocations
  • 32. Scene 1 Mistake: Coupling view components together
  • 33. MV* 101 This is how we’re taught to structure MV* applications at school.
  • 34. Sometimes it’s easier to ignore the advice We need to tell another view to do something. We’re in a rush, so we’ll just wire the dependency in and fix it later. var MyView = Mn.ItemView.extend({ ... onActionClicked: function() { this.options.anotherView.doSomething(); }, }) var myView = new MyView({ anotherView: anotherView });
  • 35. Pretty soon we’ve got a tightly coupled mess
  • 36. This makes change hard Just try to: • Move a view within the view hierarchy • Remove a view in a certain environment (unauthenticated view, mobile, etc) Let’s change things around a bit…
  • 37. Marionette solutions Use a shared model and update the model wreqr, or better yet, Backbone.Radio
  • 38. Imaginary Radio Behaviour var MyView = Mn.ItemView.extend({ behaviors: { Radio: { name: 'ui', comply: { 'chat:focus': 'focusChat' … }, focusChat: function() { // .... } }); var AnotherView = Mn.ItemView.extend({ behaviors: { Radio: { name: 'ui' }, }, onActionClicked: function() { this.radio.command('chat:focus'); } }); *correct spelling
  • 39. Scene 2 Mistake: Messing with another view’s DOM
  • 40. Quick and dirty A component needs to respond to an action and change another component’s DOM… Easiest solution: just use jquery onClick: function() { $('#action-button').hide(); }
  • 41. c/c++ pointer arithmetic In c/c++, it’s possible to use pointer arithmetic to directly modify the contents of a location in memory. I’m sure you will all agree: this is a VERY BAD IDEA! bptr = (byte*) &data; bptr = bptr + 5; iptr = (int*) bptr; (*iptr) = 0xcafebabe;
  • 42. Now imagine… Your DOM is a global memory shared by all the Javascript code running in your app Each view in your app manages a distinct piece of the global memory Mutating another view’s DOM is a bit like using pointer arithmetic to change it’s memory behind it’s back Don’t do it!
  • 43. But why? Refactoring becomes a nightmare You’re creating hidden connections between views in your application.
  • 44. Scene 3 Mistake: Different module formats on the client and server
  • 45. Then Client: AMD modules with RequireJS Tests: run in a phantomjs Server: commonjs modules with nodejs Tests run in nodejs with mocha
  • 46. Now Client: commonjs modules with webpack Server: commonjs modules with nodejs Shared code is kept in shared Shared code can be tested quickly using the nodejs and mocha, without having to start a phantomjs browser
  • 47. require.ensure(); // In your backbone router.... markdown: function() { require.ensure(['views/markdown/markdownView'], function(require) { var MarkdownView = require('views/markdown/markdownView'); appView.dialogRegion.show(new MarkdownView({})); }); },
  • 49. Code Debt A lot of these problems as the result of technical debt. When we started building the project we chose Backbone, and only later did we switch to Marionette. Initially, we treated Marionette as a neat extension of Backbone, for things like CollectionViews etc so the transition was gradual and left a lot of technical debt around. Marionette 2 PR
  • 50. From a small prototype to a large application A lot of the pain we’ve experienced has been down to the fact that we started off with a small application which has grown larger and larger. Start as you mean to go on