SlideShare una empresa de Scribd logo
1 de 30
Descargar para leer sin conexión
JavaScript in the small
Satish Chandra
!
Manu Sridharan, Simon Jensen, Koushik Sen, Ming Jin
Wearables computers have
arrived
Products from Samsung, Pebble, Google, Qualcomm, Nike and Fitbit
Wearable computers
• Form factor: capable of being worn for an
extended period of time
• Smart: advanced processing and wireless
connectivity
• Programmable: extend functionality by installing
[third-party] apps
Outline
• Programming models for wearables
• Why JavaScript?
• Application memory considerations
• Evolving JavaScript
What’s different from
smartphones?
• Less resources than on a smartphone
CPU, memory, battery capacity
• No independent WAN connectivity (current generation)
Make do with Bluetooth to a host
• Smaller (or no) display
• Sensors enabled by form factor
Application models
• Standalone applications
• Applications dependent on a host (typically a
smartphone)
Bluetooth connectivity to the host
Some future devices may have direct
connectivity to the internet
Gear application model
standalone
Wearable web app
(HTML/CSS/JS)
Notification
Communication
DeviceAPI
Gear application model
companion
Wearable web app
(HTML/CSS/JS)
Notification
Communication
DeviceAPI
Host app
Notification
Communication
Template-based app model
Wearable web app*
Notification
Communication
DeviceAPI
Host app
Notification
Communication
Template manager
A template is equipped to display a JSON object in a fixed UI format.
A template manager supports a set of templates. Does not need full
web app support
Why JavaScript?
• Popular. Atwood’s law.
• Runs in smartphones, desktops, servers, and even
in embedded controllers
• Suitable for event-based programming
• Easy to build responsive UIs for various screen
resolutions (with HTML/CSS)
WearScript
• JavaScript on Google Glass
• Motivation: rapid experimentation with apps
http://www.wearscript.com/en/latest/
JS in embedded controllers
48 KB RAM32 MB RAM
JavaScript, efficiently
• Wearables are likely to have less computational
resources than smartphones
• Should wearables pay for a full-fledged JavaScript
environment?
Less memory
Expectation of longer battery life too
• What if, realistic apps on wearables need only limited
scripting support?
Memory size
2011 2012 2013 20142010
0.5G
1.0G
2.0G
?
JavaScript Memory
Best Practices
Avoid Memory Leaks
• Space leaks: objects kept reachable after last use
• If reachable, cannot be collected by GC
• With old browsers, also GC bugs with DOM objects
• Workarounds in frameworks (GWT, jQuery)
• Less of an issue with modern browsers
Leak Patterns
• Closures: sometimes retain unexpected pointers
• Detached DOM nodes: Pointers from JavaScript
heap prevent GC
• Event listeners: additional pointers must be
cleared when DOM node dies
• Standard issues: caches, etc.
Diagnosing Leaks
Heap Snapshots in Chrome Dev Tools
https://developers.google.com/chrome-developer-tools/docs/javascript-memory-profiling
“3 Snapshot” Technique
1. Take a snapshot
2. Perform possibly-leaking action
3. Do steps 1 and 2 again
4. Take a third snapshot.
5. In third snapshot, view objects allocated between
first and second snapshot (i.e., leaked objects)
Memory-Efficient Code
• Avoid hash table object representation!
• For V8 objects, stable type structure!
• Don’t delete properties
• Don’t add properties unpredictably
• Same for arrays, and avoid mixing types
Staleness
• Staleness: long gap between last use and garbage collection
!
• A high number of stale objects indicates a potential problem
!
• To prevent staleness the programmer should ensure that object
becomes unreachable sooner so they can be garbage
collected
!
• Typical causes of staleness: Closures, caches and event listeners
Object allocated! Object used! Object is unreachable!
Staleness!
Detecting Staleness
• Difficult to accomplish with periodic heap
snapshots because “use” is not recorded
• A continuous dynamic analysis that records all
allocations, reads and writes is needed
Also keep track of links between objects
Object allocated! Object used! Object is unreachable!
Staleness!
Jalangi
• Jalangi is a framework for doing record and replay
of JavaScript programs
Developed at Samsung
!
• Recorded executions can be replayed with 

different analyses
!
• Supports recording in both browser and node.js
!
• Open source: 

https://github.com/SRA-SiliconValley/jalangi
Leaner JavaScript?
Rendering
JS runtime /
GC
JS interpreter
JS libs / frameworks (jQuery)
Application
Memory usage analyses:
leak / bloat detection,
object-equality profiling
Framework 	

specialization, lazy
loading
Ahead-of-time 	

compilation
Quasi-static	

memory
management
Restricted 	

DOM API
Rendering
JS runtime /
GC
JS interpreter
JS libs / frameworks (jQuery)
Application
Memory usage analyses:
leak / bloat detection,
object-equality profiling
Framework 	

specialization, lazy
loading
Ahead-of-time
compilation
Quasi-static
memory
management
Restricted 	

DOM API
Language restrictions
Language Restrictions
• asm.js
Only typed array
Enabler for AOT compilation: no GC, no unboxing, no runtime
checks, efficient loads and stores, etc
• LLJS
C-like, manual memory management. (asm.js with C-like
syntactic sugar)
• Statically type-able subsets
• Other proposals (interest from ECMA?)
Espruino
• Executes from source!
• Every datatype is allocated
in a 20-byte chunk (strings
and typed arrays are
packed)
• Objects use two chunks per
(key, value) pair
• Reference counting and
occasional mark-and-
sweep
Tessel
• AOT compiles
JavaScript to Lua
byte-code outside the
device
• The device contains a
Lua JIT runtime
Questions?

Más contenido relacionado

Destacado

Cognos Online Training @ Adithya Elearning
Cognos Online Training @ Adithya ElearningCognos Online Training @ Adithya Elearning
Cognos Online Training @ Adithya Elearningshanmukha rao dondapati
 
World is magnifique april 2014
World is magnifique april 2014World is magnifique april 2014
World is magnifique april 2014Prakash Montroy
 
標準人壽iOS 應用程式 - 更改未來供款分配
標準人壽iOS 應用程式 - 更改未來供款分配標準人壽iOS 應用程式 - 更改未來供款分配
標準人壽iOS 應用程式 - 更改未來供款分配StandardlifeAEM
 
Web components presentation at samsung
Web components presentation at samsungWeb components presentation at samsung
Web components presentation at samsungSeo-Young Hwang
 
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.com
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.comLA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.com
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.comCentea Infonómics
 
標準人壽 My Smart Planner Android應用程式 - 更改未來供款
標準人壽 My Smart Planner Android應用程式 - 更改未來供款標準人壽 My Smart Planner Android應用程式 - 更改未來供款
標準人壽 My Smart Planner Android應用程式 - 更改未來供款StandardlifeAEM
 
Prsa webinar part 1 final
Prsa webinar part 1 finalPrsa webinar part 1 final
Prsa webinar part 1 finalKarrieTowsley
 
PRESENTASI SIDANG KERJA PRAKTEK
PRESENTASI SIDANG KERJA PRAKTEKPRESENTASI SIDANG KERJA PRAKTEK
PRESENTASI SIDANG KERJA PRAKTEKFahrul Sunandri
 
Pp awp presentation_d1
Pp awp presentation_d1Pp awp presentation_d1
Pp awp presentation_d1Kristin Cerda
 

Destacado (16)

Tic´s Informatica
Tic´s InformaticaTic´s Informatica
Tic´s Informatica
 
Cognos Online Training @ Adithya Elearning
Cognos Online Training @ Adithya ElearningCognos Online Training @ Adithya Elearning
Cognos Online Training @ Adithya Elearning
 
World is magnifique april 2014
World is magnifique april 2014World is magnifique april 2014
World is magnifique april 2014
 
Diabetes mellitus
Diabetes mellitusDiabetes mellitus
Diabetes mellitus
 
אדם
אדםאדם
אדם
 
標準人壽iOS 應用程式 - 更改未來供款分配
標準人壽iOS 應用程式 - 更改未來供款分配標準人壽iOS 應用程式 - 更改未來供款分配
標準人壽iOS 應用程式 - 更改未來供款分配
 
Ed unit 1
Ed unit  1Ed unit  1
Ed unit 1
 
Asuhan kebidanan persalinan
Asuhan kebidanan persalinanAsuhan kebidanan persalinan
Asuhan kebidanan persalinan
 
Web components presentation at samsung
Web components presentation at samsungWeb components presentation at samsung
Web components presentation at samsung
 
Itc sec1
Itc sec1Itc sec1
Itc sec1
 
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.com
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.comLA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.com
LA FÒRMULA DE L'ÈXIT - Susana Artó - www.confiaconsulting.com
 
標準人壽 My Smart Planner Android應用程式 - 更改未來供款
標準人壽 My Smart Planner Android應用程式 - 更改未來供款標準人壽 My Smart Planner Android應用程式 - 更改未來供款
標準人壽 My Smart Planner Android應用程式 - 更改未來供款
 
Js on-microcontrollers
Js on-microcontrollersJs on-microcontrollers
Js on-microcontrollers
 
Prsa webinar part 1 final
Prsa webinar part 1 finalPrsa webinar part 1 final
Prsa webinar part 1 final
 
PRESENTASI SIDANG KERJA PRAKTEK
PRESENTASI SIDANG KERJA PRAKTEKPRESENTASI SIDANG KERJA PRAKTEK
PRESENTASI SIDANG KERJA PRAKTEK
 
Pp awp presentation_d1
Pp awp presentation_d1Pp awp presentation_d1
Pp awp presentation_d1
 

Similar a SWTT 140407 session04

Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleIT Arena
 
Building Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on AzureBuilding Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on AzureBrian Lyttle
 
GWT HJUG Presentation
GWT HJUG PresentationGWT HJUG Presentation
GWT HJUG PresentationDerrick Bowen
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Ivano Malavolta
 
Developing Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapDeveloping Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapAmar Mesic
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applicationsIvano Malavolta
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for EngineersBrian LeRoux
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalRAdam Mokan
 
Seattle bestpractices2010
Seattle bestpractices2010Seattle bestpractices2010
Seattle bestpractices2010Olaseni Odebiyi
 
The Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesThe Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesWesley Hales
 
Android Training in Chandigarh
Android Training in ChandigarhAndroid Training in Chandigarh
Android Training in ChandigarhArcadian Learning
 

Similar a SWTT 140407 session04 (20)

Hybrid mobile apps
Hybrid mobile appsHybrid mobile apps
Hybrid mobile apps
 
Meetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech PeopleMeetup. Technologies Intro for Non-Tech People
Meetup. Technologies Intro for Non-Tech People
 
Building Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on AzureBuilding Mobile Web Apps with jQM and Cordova on Azure
Building Mobile Web Apps with jQM and Cordova on Azure
 
Service worker API
Service worker APIService worker API
Service worker API
 
20120306 dublin js
20120306 dublin js20120306 dublin js
20120306 dublin js
 
GWT HJUG Presentation
GWT HJUG PresentationGWT HJUG Presentation
GWT HJUG Presentation
 
wt mod3.pdf
wt mod3.pdfwt mod3.pdf
wt mod3.pdf
 
Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app Anatomy of an HTML 5 mobile web app
Anatomy of an HTML 5 mobile web app
 
Software Engineering 2014
Software Engineering 2014Software Engineering 2014
Software Engineering 2014
 
Developing Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGapDeveloping Windows Phone 8 apps using PhoneGap
Developing Windows Phone 8 apps using PhoneGap
 
Fast Cordova applications
Fast Cordova applicationsFast Cordova applications
Fast Cordova applications
 
Phonegap for Engineers
Phonegap for EngineersPhonegap for Engineers
Phonegap for Engineers
 
Introduction to SignalR
Introduction to SignalRIntroduction to SignalR
Introduction to SignalR
 
20120802 timisoara
20120802 timisoara20120802 timisoara
20120802 timisoara
 
Seattle bestpractices2010
Seattle bestpractices2010Seattle bestpractices2010
Seattle bestpractices2010
 
Android quick talk
Android quick talkAndroid quick talk
Android quick talk
 
The Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devicesThe Mobile Web - HTML5 on mobile devices
The Mobile Web - HTML5 on mobile devices
 
Eureko frameworks
Eureko frameworksEureko frameworks
Eureko frameworks
 
Android Training in Chandigarh
Android Training in ChandigarhAndroid Training in Chandigarh
Android Training in Chandigarh
 
The Java alternative to Javascript
The Java alternative to JavascriptThe Java alternative to Javascript
The Java alternative to Javascript
 

Último

Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024D Cloud Solutions
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPathCommunity
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfDaniel Santiago Silva Capera
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxGDSC PJATK
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxMatsuo Lab
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...Aggregage
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UbiTrack UK
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IES VE
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemAsko Soukka
 

Último (20)

Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024Artificial Intelligence & SEO Trends for 2024
Artificial Intelligence & SEO Trends for 2024
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
UiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation DevelopersUiPath Community: AI for UiPath Automation Developers
UiPath Community: AI for UiPath Automation Developers
 
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdfIaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
IaC & GitOps in a Nutshell - a FridayInANuthshell Episode.pdf
 
Cybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptxCybersecurity Workshop #1.pptx
Cybersecurity Workshop #1.pptx
 
Introduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptxIntroduction to Matsuo Laboratory (ENG).pptx
Introduction to Matsuo Laboratory (ENG).pptx
 
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
The Data Metaverse: Unpacking the Roles, Use Cases, and Tech Trends in Data a...
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
UWB Technology for Enhanced Indoor and Outdoor Positioning in Physiological M...
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
IESVE Software for Florida Code Compliance Using ASHRAE 90.1-2019
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
Bird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystemBird eye's view on Camunda open source ecosystem
Bird eye's view on Camunda open source ecosystem
 

SWTT 140407 session04

  • 1. JavaScript in the small Satish Chandra ! Manu Sridharan, Simon Jensen, Koushik Sen, Ming Jin
  • 2. Wearables computers have arrived Products from Samsung, Pebble, Google, Qualcomm, Nike and Fitbit
  • 3. Wearable computers • Form factor: capable of being worn for an extended period of time • Smart: advanced processing and wireless connectivity • Programmable: extend functionality by installing [third-party] apps
  • 4. Outline • Programming models for wearables • Why JavaScript? • Application memory considerations • Evolving JavaScript
  • 5. What’s different from smartphones? • Less resources than on a smartphone CPU, memory, battery capacity • No independent WAN connectivity (current generation) Make do with Bluetooth to a host • Smaller (or no) display • Sensors enabled by form factor
  • 6. Application models • Standalone applications • Applications dependent on a host (typically a smartphone) Bluetooth connectivity to the host Some future devices may have direct connectivity to the internet
  • 7. Gear application model standalone Wearable web app (HTML/CSS/JS) Notification Communication DeviceAPI
  • 8. Gear application model companion Wearable web app (HTML/CSS/JS) Notification Communication DeviceAPI Host app Notification Communication
  • 9. Template-based app model Wearable web app* Notification Communication DeviceAPI Host app Notification Communication Template manager A template is equipped to display a JSON object in a fixed UI format. A template manager supports a set of templates. Does not need full web app support
  • 10. Why JavaScript? • Popular. Atwood’s law. • Runs in smartphones, desktops, servers, and even in embedded controllers • Suitable for event-based programming • Easy to build responsive UIs for various screen resolutions (with HTML/CSS)
  • 11. WearScript • JavaScript on Google Glass • Motivation: rapid experimentation with apps http://www.wearscript.com/en/latest/
  • 12. JS in embedded controllers 48 KB RAM32 MB RAM
  • 13. JavaScript, efficiently • Wearables are likely to have less computational resources than smartphones • Should wearables pay for a full-fledged JavaScript environment? Less memory Expectation of longer battery life too • What if, realistic apps on wearables need only limited scripting support?
  • 14. Memory size 2011 2012 2013 20142010 0.5G 1.0G 2.0G ?
  • 16. Avoid Memory Leaks • Space leaks: objects kept reachable after last use • If reachable, cannot be collected by GC • With old browsers, also GC bugs with DOM objects • Workarounds in frameworks (GWT, jQuery) • Less of an issue with modern browsers
  • 17. Leak Patterns • Closures: sometimes retain unexpected pointers • Detached DOM nodes: Pointers from JavaScript heap prevent GC • Event listeners: additional pointers must be cleared when DOM node dies • Standard issues: caches, etc.
  • 18. Diagnosing Leaks Heap Snapshots in Chrome Dev Tools https://developers.google.com/chrome-developer-tools/docs/javascript-memory-profiling
  • 19. “3 Snapshot” Technique 1. Take a snapshot 2. Perform possibly-leaking action 3. Do steps 1 and 2 again 4. Take a third snapshot. 5. In third snapshot, view objects allocated between first and second snapshot (i.e., leaked objects)
  • 20. Memory-Efficient Code • Avoid hash table object representation! • For V8 objects, stable type structure! • Don’t delete properties • Don’t add properties unpredictably • Same for arrays, and avoid mixing types
  • 21. Staleness • Staleness: long gap between last use and garbage collection ! • A high number of stale objects indicates a potential problem ! • To prevent staleness the programmer should ensure that object becomes unreachable sooner so they can be garbage collected ! • Typical causes of staleness: Closures, caches and event listeners Object allocated! Object used! Object is unreachable! Staleness!
  • 22. Detecting Staleness • Difficult to accomplish with periodic heap snapshots because “use” is not recorded • A continuous dynamic analysis that records all allocations, reads and writes is needed Also keep track of links between objects Object allocated! Object used! Object is unreachable! Staleness!
  • 23. Jalangi • Jalangi is a framework for doing record and replay of JavaScript programs Developed at Samsung ! • Recorded executions can be replayed with 
 different analyses ! • Supports recording in both browser and node.js ! • Open source: 
 https://github.com/SRA-SiliconValley/jalangi
  • 25. Rendering JS runtime / GC JS interpreter JS libs / frameworks (jQuery) Application Memory usage analyses: leak / bloat detection, object-equality profiling Framework specialization, lazy loading Ahead-of-time compilation Quasi-static memory management Restricted DOM API
  • 26. Rendering JS runtime / GC JS interpreter JS libs / frameworks (jQuery) Application Memory usage analyses: leak / bloat detection, object-equality profiling Framework specialization, lazy loading Ahead-of-time compilation Quasi-static memory management Restricted DOM API Language restrictions
  • 27. Language Restrictions • asm.js Only typed array Enabler for AOT compilation: no GC, no unboxing, no runtime checks, efficient loads and stores, etc • LLJS C-like, manual memory management. (asm.js with C-like syntactic sugar) • Statically type-able subsets • Other proposals (interest from ECMA?)
  • 28. Espruino • Executes from source! • Every datatype is allocated in a 20-byte chunk (strings and typed arrays are packed) • Objects use two chunks per (key, value) pair • Reference counting and occasional mark-and- sweep
  • 29. Tessel • AOT compiles JavaScript to Lua byte-code outside the device • The device contains a Lua JIT runtime