SlideShare a Scribd company logo
You don’t know JS about SharePoint - Mastering JavaScript performance
SharePoint Konferenz Erding
Hugh Wood – Master Chief – Rencore AB - @HughAJWood
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
AJAX
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
AJAX XHR - XMLHttpRequest
function request(method, url) {
return new Promise(function (resolve, reject) {
var xhr = new XMLHttpRequest();
xhr.open(method, url);
xhr.onload = resolve;
xhr.onerror = reject;
xhr.send();
});
}
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
jQuery – AJAX + Deferreds
$.when( $.ajax( "test.aspx" ) ).then(function( data, textStatus, jqXHR ) {
log( jqXHR.status );
});
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
jQuery – executeQueryAsync + Deferreds
// Wrap executeQueryAsync to use jQuery deferred
function executeQueryAsync(item, task) {
var dfd = $.Deferred();
context.executeQueryAsync(function() {
if (typeof task == 'function') {
task.call();
}
dfd.resolve(item);
}, function(sender, args) {
dfd.reject();
});
return dfd;
}
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Queuing Async Operations
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Queuing Async Operations
var taskQueue = [],
xhrXimit = 5,
xhrThreads = 0;
function queueTask(method, url) {
queue.push({"method":method, "url":url});
}
function executeQueueTask() {
// Nothing to do
if(myQueue.length === 0 || xhrThreads >= xhrLimit) return;
var task = queue.shift();
xhrThreads++;
request(task.method, task.url).then(function() { xhrThreads--; });
}
queueTask("POST", "/v1/public/characters/1009268");
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Loop Performance
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Loop Performance
https://jsperf.com/fastest-array-loops-in-javascript/515
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Loop Performance – Winner Overall
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Loop Performance – The real winner
while( i = arr.pop() ) {
someFn(i);
}
10934% ~ 15417% in all browsers than a regular for loop
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Loop Performance
JavaScript Code
Abstract Syntax
Tree
Native Code
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Reference Performance
// Copy Reference
var len = arr.length;
// y is slower to access as you have to go through x
var a = x.y;
// z is even slower! x->y->z
var b = x.y.z;
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Reference Performance
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Reference Performance
http://jsperf.com/object-reference-performance-tests
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Asynchronous Control
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Asynchronous Control - Promises
fulfilled - The action relating to the promise succeeded
rejected - The action relating to the promise failed
pending - Hasn't fulfilled or rejected yet
settled - Has fulfilled or rejected
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Asynchronous Control - Promises
promise.then(function(n) {
// 1
log(n);
return n + 1;
}).then(function(n) {
// 3
log(n);
});
var promise = new Promise(function(resolve, reject) {
resolve(1);
});
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Asynchronous Control - Promises
PROMISES ARE SLOW!!!!
Are they?
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Asynchronous Control - Promises
PROMISES SCALE
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Efficiency - Declaration
// Results in multiple copies of foo
baz.Bar = function() {
// constructor body
this.foo = function() {
// method body
};
}
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Efficiency - Declaration
// Results in multiple copies of foo
baz.Bar = function() {
// constructor body
this.foo = function() {
// method body
};
}
// Results in a singular copy of foo
baz.Bar = function() {
// constructor body
};
baz.Bar.prototype.foo = function() {
// method body
};
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Efficiency - Functions
function setupAlertTimeout() {
var msg = 'Message to alert';
window.setTimeout(function() { alert(msg); }, 100);
}
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Efficiency - Functions
function setupAlertTimeout() {
var msg = 'Message to alert';
window.setTimeout(function() { alert(msg); }, 100);
}
function alertMsg() {
var msg = 'Message to alert';
alert(msg);
}
function setupAlertTimeout() {
window.setTimeout(alertMsg, 100);
}
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Leaks
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Leaks
var run = function () {
var str = new Array(1000000).join('*');
var doSomethingWithStr = function () {
if (str === 'something')
console.log("str was something");
};
doSomethingWithStr();
var logIt = function () {
console.log('interval');
}
setInterval(logIt, 100);
};
setInterval(run, 1000);
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Leaks
$('<div/>')
.html(new Array(1000).join('text'))
.click(function() { })
.appendTo('#data');
document.getElementById('data').innerHTML = '';
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
Memory Leaks
$('<div/>')
.html(new Array(1000).join('text'))
.click(function() { })
.appendTo('#data');
document.getElementById('data').innerHTML = '';
Ajax performance
Loop performance
Memory reference performance
Asynchronous control
Memory Efficiency
Memory Leaks
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
@HughAJWood
https//blog.spcaf.com Hugh.Wood@Rencore.com
Hugh Wood
Leicester, England
Master Chief @ Rencore GmbH
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood

More Related Content

PDF
Extending the WordPress REST API - Josh Pollock
PPT
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
PDF
Using the new WordPress REST API
PDF
Introduction to AngularJS For WordPress Developers
KEY
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
PPTX
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
PDF
Full Stack Toronto - the 3R Stack
PDF
Django Rest Framework and React and Redux, Oh My!
Extending the WordPress REST API - Josh Pollock
Task Scheduling and Asynchronous Processing Evolved. Zend Server Job Queue
Using the new WordPress REST API
Introduction to AngularJS For WordPress Developers
Single Page Web Applications with CoffeeScript, Backbone and Jasmine
WordCamp Ann Arbor 2015 Introduction to Backbone + WP REST API
Full Stack Toronto - the 3R Stack
Django Rest Framework and React and Redux, Oh My!

What's hot (20)

PDF
Hybrid Web Applications
PDF
Otimizando Aplicações em Rails
PDF
How to replace rails asset pipeline with webpack?
PDF
Os Pruett
PPTX
Working with WP_Query in WordPress
PDF
WordPress APIs
PPT
Zend - Installation And Sample Project Creation
KEY
Loadrunner
PDF
Workshop 6: Designer tools
PDF
Caldera Learn - LoopConf WP API + Angular FTW Workshop
KEY
Alpha Streaming Realtime
PPT
Zend Con 2008 Slides
KEY
Geotalk presentation
PDF
clara-rules
PDF
Inside Bokete: Web Application with Mojolicious and others
PPTX
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
PDF
Os Furlong
PPTX
Express JS
PPTX
Express JS
PDF
Os Bunce
Hybrid Web Applications
Otimizando Aplicações em Rails
How to replace rails asset pipeline with webpack?
Os Pruett
Working with WP_Query in WordPress
WordPress APIs
Zend - Installation And Sample Project Creation
Loadrunner
Workshop 6: Designer tools
Caldera Learn - LoopConf WP API + Angular FTW Workshop
Alpha Streaming Realtime
Zend Con 2008 Slides
Geotalk presentation
clara-rules
Inside Bokete: Web Application with Mojolicious and others
SaaSy maps - using django-tenants and geodjango to provide web-gis software-a...
Os Furlong
Express JS
Express JS
Os Bunce
Ad

Similar to You don’t know JS about SharePoint - Mastering javascript performance (Hugh Wood) (20)

PDF
Ten useful JavaScript tips & best practices
PDF
JavaScript and jQuery for SharePoint Developers
PPTX
SharePoint Cincy 2012 - jQuery essentials
PPTX
Client Object Model - SharePoint Extreme 2012
PPTX
Windows 8 JavaScript (Wonderland)
PDF
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
PPTX
SPSTC - SharePoint & jQuery Essentials
PPTX
SharePoint Saturday Atlanta 2015
PDF
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
PPTX
Power to the People: Manipulating SharePoint with Client-Side JavaScript
PPTX
Async & Parallel in JavaScript
PPTX
Building high performance
PDF
Rencore Webinar: Developing Secure and Performant JavaScript for SharePoint
PPT
Learn ASP.NET AJAX in 5 Minutes
PPT
Ajax Performance
PPTX
JavaScript front end performance optimizations
PPTX
SharePoint Saturday St. Louis - SharePoint & jQuery
PPTX
Spsemea j query
PDF
Building windows8 modern app for sp2013
PPTX
JavaScript Performance Patterns
Ten useful JavaScript tips & best practices
JavaScript and jQuery for SharePoint Developers
SharePoint Cincy 2012 - jQuery essentials
Client Object Model - SharePoint Extreme 2012
Windows 8 JavaScript (Wonderland)
How DRY impacts JavaScript performance // Faster JavaScript execution for the...
SPSTC - SharePoint & jQuery Essentials
SharePoint Saturday Atlanta 2015
The Magic Revealed: Four Real-World Examples of Using the Client Object Model...
Power to the People: Manipulating SharePoint with Client-Side JavaScript
Async & Parallel in JavaScript
Building high performance
Rencore Webinar: Developing Secure and Performant JavaScript for SharePoint
Learn ASP.NET AJAX in 5 Minutes
Ajax Performance
JavaScript front end performance optimizations
SharePoint Saturday St. Louis - SharePoint & jQuery
Spsemea j query
Building windows8 modern app for sp2013
JavaScript Performance Patterns
Ad

More from Rencore (10)

PPTX
Rencore Webinar: 10 things to keep an eye on to increase share point health
PPTX
Provisioning SPFx Solutions to SharePoint Online using PnP, ALM APIs and more!
PDF
Rencore Webinar: Myth-busting GDPR in Office 365 & Azure
PPTX
Hugh Wood from Rencore: Development best practices for a new development worl...
PPTX
Matthias Einig from Rencore: Organizational considerations for customizing Sh...
PPTX
Rencore Webinar: Understanding EU GDPR from an Office 365 perspective with Pa...
PDF
Rencore Webinar: Advanced Security Management within Office 365 with Liam Cleary
PDF
Matthias Einig from Rencore - Transforming SharePoint farm solutions to the A...
PPTX
Rencore Webinar: Securing Office 365 and Microsoft Azure like a Rockstar
PPTX
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...
Rencore Webinar: 10 things to keep an eye on to increase share point health
Provisioning SPFx Solutions to SharePoint Online using PnP, ALM APIs and more!
Rencore Webinar: Myth-busting GDPR in Office 365 & Azure
Hugh Wood from Rencore: Development best practices for a new development worl...
Matthias Einig from Rencore: Organizational considerations for customizing Sh...
Rencore Webinar: Understanding EU GDPR from an Office 365 perspective with Pa...
Rencore Webinar: Advanced Security Management within Office 365 with Liam Cleary
Matthias Einig from Rencore - Transforming SharePoint farm solutions to the A...
Rencore Webinar: Securing Office 365 and Microsoft Azure like a Rockstar
Rencore Webinar: SharePoint Customizations - the most overlooked road block t...

Recently uploaded (20)

PPTX
MYSQL Presentation for SQL database connectivity
PDF
Per capita expenditure prediction using model stacking based on satellite ima...
PDF
Empathic Computing: Creating Shared Understanding
PDF
Chapter 2 Digital Image Fundamentals.pdf
PDF
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
PDF
NewMind AI Monthly Chronicles - July 2025
PDF
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
PDF
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
PDF
NewMind AI Weekly Chronicles - August'25 Week I
PPTX
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
PPTX
Understanding_Digital_Forensics_Presentation.pptx
PDF
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
PDF
Spectral efficient network and resource selection model in 5G networks
PDF
Diabetes mellitus diagnosis method based random forest with bat algorithm
PDF
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
PDF
Review of recent advances in non-invasive hemoglobin estimation
PDF
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
PPTX
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
PDF
Reach Out and Touch Someone: Haptics and Empathic Computing
PPTX
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication
MYSQL Presentation for SQL database connectivity
Per capita expenditure prediction using model stacking based on satellite ima...
Empathic Computing: Creating Shared Understanding
Chapter 2 Digital Image Fundamentals.pdf
CIFDAQ's Market Wrap: Ethereum Leads, Bitcoin Lags, Institutions Shift
NewMind AI Monthly Chronicles - July 2025
How UI/UX Design Impacts User Retention in Mobile Apps.pdf
Bridging biosciences and deep learning for revolutionary discoveries: a compr...
NewMind AI Weekly Chronicles - August'25 Week I
breach-and-attack-simulation-cybersecurity-india-chennai-defenderrabbit-2025....
Understanding_Digital_Forensics_Presentation.pptx
TokAI - TikTok AI Agent : The First AI Application That Analyzes 10,000+ Vira...
Spectral efficient network and resource selection model in 5G networks
Diabetes mellitus diagnosis method based random forest with bat algorithm
HCSP-Presales-Campus Network Planning and Design V1.0 Training Material-Witho...
Review of recent advances in non-invasive hemoglobin estimation
Blue Purple Modern Animated Computer Science Presentation.pdf.pdf
Comunidade Salesforce São Paulo - Desmistificando o Omnistudio (Vlocity)
Reach Out and Touch Someone: Haptics and Empathic Computing
PA Analog/Digital System: The Backbone of Modern Surveillance and Communication

You don’t know JS about SharePoint - Mastering javascript performance (Hugh Wood)

  • 1. You don’t know JS about SharePoint - Mastering JavaScript performance SharePoint Konferenz Erding Hugh Wood – Master Chief – Rencore AB - @HughAJWood
  • 2. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood AJAX
  • 3. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood AJAX XHR - XMLHttpRequest function request(method, url) { return new Promise(function (resolve, reject) { var xhr = new XMLHttpRequest(); xhr.open(method, url); xhr.onload = resolve; xhr.onerror = reject; xhr.send(); }); }
  • 4. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood jQuery – AJAX + Deferreds $.when( $.ajax( "test.aspx" ) ).then(function( data, textStatus, jqXHR ) { log( jqXHR.status ); });
  • 5. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood jQuery – executeQueryAsync + Deferreds // Wrap executeQueryAsync to use jQuery deferred function executeQueryAsync(item, task) { var dfd = $.Deferred(); context.executeQueryAsync(function() { if (typeof task == 'function') { task.call(); } dfd.resolve(item); }, function(sender, args) { dfd.reject(); }); return dfd; }
  • 6. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Queuing Async Operations
  • 7. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Queuing Async Operations var taskQueue = [], xhrXimit = 5, xhrThreads = 0; function queueTask(method, url) { queue.push({"method":method, "url":url}); } function executeQueueTask() { // Nothing to do if(myQueue.length === 0 || xhrThreads >= xhrLimit) return; var task = queue.shift(); xhrThreads++; request(task.method, task.url).then(function() { xhrThreads--; }); } queueTask("POST", "/v1/public/characters/1009268");
  • 8. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Loop Performance
  • 9. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Loop Performance https://jsperf.com/fastest-array-loops-in-javascript/515
  • 10. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Loop Performance – Winner Overall
  • 11. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Loop Performance – The real winner while( i = arr.pop() ) { someFn(i); } 10934% ~ 15417% in all browsers than a regular for loop
  • 12. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Loop Performance JavaScript Code Abstract Syntax Tree Native Code
  • 13. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Reference Performance // Copy Reference var len = arr.length; // y is slower to access as you have to go through x var a = x.y; // z is even slower! x->y->z var b = x.y.z;
  • 14. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Reference Performance
  • 15. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Reference Performance http://jsperf.com/object-reference-performance-tests
  • 16. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Asynchronous Control
  • 17. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Asynchronous Control - Promises fulfilled - The action relating to the promise succeeded rejected - The action relating to the promise failed pending - Hasn't fulfilled or rejected yet settled - Has fulfilled or rejected
  • 18. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Asynchronous Control - Promises promise.then(function(n) { // 1 log(n); return n + 1; }).then(function(n) { // 3 log(n); }); var promise = new Promise(function(resolve, reject) { resolve(1); });
  • 19. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Asynchronous Control - Promises PROMISES ARE SLOW!!!! Are they?
  • 20. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Asynchronous Control - Promises PROMISES SCALE
  • 21. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Efficiency - Declaration // Results in multiple copies of foo baz.Bar = function() { // constructor body this.foo = function() { // method body }; }
  • 22. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Efficiency - Declaration // Results in multiple copies of foo baz.Bar = function() { // constructor body this.foo = function() { // method body }; } // Results in a singular copy of foo baz.Bar = function() { // constructor body }; baz.Bar.prototype.foo = function() { // method body };
  • 23. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Efficiency - Functions function setupAlertTimeout() { var msg = 'Message to alert'; window.setTimeout(function() { alert(msg); }, 100); }
  • 24. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Efficiency - Functions function setupAlertTimeout() { var msg = 'Message to alert'; window.setTimeout(function() { alert(msg); }, 100); } function alertMsg() { var msg = 'Message to alert'; alert(msg); } function setupAlertTimeout() { window.setTimeout(alertMsg, 100); }
  • 25. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Leaks
  • 26. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Leaks var run = function () { var str = new Array(1000000).join('*'); var doSomethingWithStr = function () { if (str === 'something') console.log("str was something"); }; doSomethingWithStr(); var logIt = function () { console.log('interval'); } setInterval(logIt, 100); }; setInterval(run, 1000);
  • 27. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Leaks $('<div/>') .html(new Array(1000).join('text')) .click(function() { }) .appendTo('#data'); document.getElementById('data').innerHTML = '';
  • 28. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood Memory Leaks $('<div/>') .html(new Array(1000).join('text')) .click(function() { }) .appendTo('#data'); document.getElementById('data').innerHTML = '';
  • 29. Ajax performance Loop performance Memory reference performance Asynchronous control Memory Efficiency Memory Leaks You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
  • 30. @HughAJWood https//blog.spcaf.com [email protected] Hugh Wood Leicester, England Master Chief @ Rencore GmbH You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood
  • 31. You don’t know JS about SharePoint - Mastering JavaScript performance - @HughAJWood