SlideShare a Scribd company logo
1 of 24
Download to read offline
JavaScript on Microcontrollers 
Samsung Open Source Group 1 
Tilmann Scheller 
LLVM Compiler Engineer 
t.scheller@samsung.com 
Samsung Open Source Group 
Samsung Research UK 
2nd Samsung Web Tech Talk 
San Jose, USA, October 30, 2014
Overview 
● Introduction 
● JavaScript engine code size 
● JavaScript engine correctness/performance 
● Summary 
Samsung Open Source Group 2
Introduction 
Samsung Open Source Group 3
Introduction 
● Wearable devices becoming more and more widespread 
● Weight and energy efficiency a big concern 
● JavaScript very popular, easy to learn 
● Scales from embedded to servers 
● Execute JavaScript on a microcontroller! 
Samsung Open Source Group 4
Target hardware 
● Cortex-M3 microcontroller (32-bit ARM Thumb-2) 
● 96KB of RAM 
● 512KB of flash memory 
● Clocked at 84MHz 
Samsung Open Source Group 5
JS Engines 
● Goal: JS engine which fits in the microcontroller 
constraints 
● Option one: Pick an established JS engine and strip it 
down to fit on a microcontroller 
● Option two: Pick a lightweight engine and make sure that 
it meets all the requirements 
Samsung Open Source Group 6
JS Engines 
● Two approaches pursued in parallel: 
– Try to minimize JavaScriptCore so that it fits on a 
microcontroller 
– Get the lightweight Duktape engine running on a 
microcontroller 
Samsung Open Source Group 7
JavaScriptCore 
● Well-established JS engine running on millions of devices 
● High-performance (four distinct levels of optimization) 
● Never intended to run in resource-constrained 
environments, primary focus is maximum performance 
● Written in C++ 
Samsung Open Source Group 8
Duktape 
● Lightweight JS engine 
● Focus on portability and a low footprint 
● Written in C and about 40k lines of code (excluding 
comments) 
● ECMAScript E5/E5.1 compliant 
● Liberal license 
● Active community, has been around for several years 
Samsung Open Source Group 9
Code size 
Samsung Open Source Group 10
JavaScriptCore minimization 
● Challenge: JavaScriptCore was never intended for 
environments like this 
● First attempt: 
– Took r170522 (June 26, 2014) of WebKit and built the EFL 
configuration for Thumb-2 
● Original (3.63 MB) 
● Reduced (2.39 MB) 
● Static (21.21 MB) 
– Several MB of heap memory consumed during runtime 
Samsung Open Source Group 11
JavaScriptCore minimization 
● Current snapshot: way too big! 
● Second try: Use a snapshot from 2008 just before SquirrelFish was merged 
● Performed minimizations: 
– Qt dependency was removed 
– Reduced the size of ICU data by disabling extra features 
– Rebuilt ICU with the –Os compiler option 
– Pthread was removed 
– Built older ICU libs 
– Stripped static JSC binary is now 1,647 KB (was: 19,578 KB) 
– The engine part of is 311 KB 
– The Unicode libraries are 562 Kbyte and the remaining size comes from libc, libm 
and libstdc++ libraries. 
Samsung Open Source Group 12
JavaScriptCore minimization 
● Engine size close to target size 
● However, libraries rely on too many system calls to make 
it feasible to run on a baremetal system 
● Too much effort to get JSC working on a baremetal 
system 
● Aborting JSC investigation and directing all efforts 
towards Duktape 
Samsung Open Source Group 13
Duktape 
● Compiled for Thumb-2 
● Using the newlib C standard library 
● No OS running on the microcontroller 
● Statically linked binary 
● C library has a big impact on the size of the executable 
● Disabling certain optimizations (through preprocessor 
macros), helps to reduce code size even further 
Samsung Open Source Group 14
Code size 
Static binary 
Engine 
Libraries 
108 
161 
100 
83 
70 
59 
212 
187 
127 
318 
655 
790 
1207 
311 
0 200 400 600 800 1000 1200 1400 1600 1800 
Samsung Open Source Group 15 
1647 
Duktape Thumb-2 baremetal noopt 
Duktape Thumb-2 baremetal 
Duktape ARM baremetal 
Duktape ARM Linux glibc 
JSC Thumb-2 Linux glibc 
KB 
Compiled at -Os ..., noopt = Duktape optimizations not compiled in, 
baremetal builds link against Newlib
Correctness/Performance 
Samsung Open Source Group 16
Correctness - test262 
● Duktape 0.12 and Arduino library 1.5.8, without DUK_OPT defines 
● test262 (ECMAScript conformance test suite) results: 
– Ran 11824 tests 
● Passed 11411 tests (96.5%) 
● Failed 413 tests (3.5%) 
● Failure details: 
– 144 tests ran out of memory 
– 10 tests timed out (300 secs) 
– 90 tests failed because of an undefined gettimeofday() function 
– 169 tests fail because of other reasons (have to be investigated) 
– Summary: 167 failures specific to the Arduino Due and 246 tests which fail on 
x86-64 as well 
Samsung Open Source Group 17
test262 
85 713 
288957 
Min Avg Max 
350000 
300000 
250000 
200000 
150000 
100000 
50000 
0 
Execution time (ms) 
Samsung Open Source Group 18 
Min Avg Max 
80 
70 
60 
50 
40 
30 
20 
10 
0 
54 
57 
75 
Memory usage (KB)
SunSpider 
● Duktape 0.12 and Arduino library 1.5.8, without DUK_OPT defines 
● Ran 26 tests 
– Passed 9 tests (34.6%) 
– Failed 17 tests (65.4%) 
● Failure details: 
– 3 tests were too big (string-unpack-code.js (164K), string-tagcloud.js 
(172K), regexp-dna.js (400K)) 
– 13 tests run out of memory (3d-cube.js, 3d-morph.js, 3d-raytrace.js, 
access-binary-trees.js, access-nsieve.js, bitops-nsieve-bits.js, crypto-aes.js, 
crypto-md5.js, crypto-sha1.js, date-format-tofte.js, date-format-xparb.js, 
string-base64.js, string-validate-input.js) 
– 1 test failed because of undefined gettimeofday() function (math-cordic.js) 
Samsung Open Source Group 19
SunSpider 
access-nbody 
160 
140 
120 
100 
80 
60 
40 
20 
access-fannkuch 
bitops-bits-in-byte 
bitops-3bit-bits-in-byte 
controlflow-recursive 
bitops-bitwise-and 
math-partial-sums 
Samsung Open Source Group 20 
math-spectral-norm 
string-fasta 
0 
149 
41.5 
64.3 
74.8 
140.2 
25.9 
62.3 
21.8 
119.9 
54 
64 
50 49 50 
70 
51 53 57 
Execution time (s) 
Memory usage (KB)
Summary 
Samsung Open Source Group 21
Summary 
● JavaScriptCore proved to be unsuitable for 
microcontrollers 
● Duktape fits well into flash and main memory 
● Duktape has promising correctness results 
● Ongoing effort to evaluate Duktape performance 
Samsung Open Source Group 22
Thank you. 
Samsung Open Source Group 23
We are hiring! 
Contact Information: 
Tilmann Scheller 
t.scheller@samsung.com 
Samsung Open Source Group 
Samsung Research UK 
Samsung Open Source Group 24

More Related Content

What's hot

OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJava
William Au
 
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
ScyllaDB
 
OpenNebulaconf2017US: Rapid scaling of research computing to over 70,000 cor...
OpenNebulaconf2017US:  Rapid scaling of research computing to over 70,000 cor...OpenNebulaconf2017US:  Rapid scaling of research computing to over 70,000 cor...
OpenNebulaconf2017US: Rapid scaling of research computing to over 70,000 cor...
OpenNebula Project
 

What's hot (20)

Le guide de dépannage de la jvm
Le guide de dépannage de la jvmLe guide de dépannage de la jvm
Le guide de dépannage de la jvm
 
Tools for Metaspace
Tools for MetaspaceTools for Metaspace
Tools for Metaspace
 
Using Flame Graphs
Using Flame GraphsUsing Flame Graphs
Using Flame Graphs
 
OSCON2012TroubleShootJava
OSCON2012TroubleShootJavaOSCON2012TroubleShootJava
OSCON2012TroubleShootJava
 
Software Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in JavaSoftware Profiling: Understanding Java Performance and how to profile in Java
Software Profiling: Understanding Java Performance and how to profile in Java
 
Multimaster
MultimasterMultimaster
Multimaster
 
Tuning Linux for MongoDB
Tuning Linux for MongoDBTuning Linux for MongoDB
Tuning Linux for MongoDB
 
On the benchmark of Chainer
On the benchmark of ChainerOn the benchmark of Chainer
On the benchmark of Chainer
 
Jvm problem diagnostics
Jvm problem diagnosticsJvm problem diagnostics
Jvm problem diagnostics
 
Get Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java ApplicationsGet Lower Latency and Higher Throughput for Java Applications
Get Lower Latency and Higher Throughput for Java Applications
 
Java GC, Off-heap workshop
Java GC, Off-heap workshopJava GC, Off-heap workshop
Java GC, Off-heap workshop
 
LXC on Ganeti
LXC on GanetiLXC on Ganeti
LXC on Ganeti
 
Elephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forksElephant Roads: a tour of Postgres forks
Elephant Roads: a tour of Postgres forks
 
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
OSv Unikernel — Optimizing Guest OS to Run Stateless and Serverless Apps in t...
 
GitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons LearnedGitLab PostgresMortem: Lessons Learned
GitLab PostgresMortem: Lessons Learned
 
OpenNebulaconf2017US: Rapid scaling of research computing to over 70,000 cor...
OpenNebulaconf2017US:  Rapid scaling of research computing to over 70,000 cor...OpenNebulaconf2017US:  Rapid scaling of research computing to over 70,000 cor...
OpenNebulaconf2017US: Rapid scaling of research computing to over 70,000 cor...
 
Bpf performance tools chapter 4 bcc
Bpf performance tools chapter 4   bccBpf performance tools chapter 4   bcc
Bpf performance tools chapter 4 bcc
 
cache2k, Java Caching, Turbo Charged, FOSDEM 2015
cache2k, Java Caching, Turbo Charged, FOSDEM 2015cache2k, Java Caching, Turbo Charged, FOSDEM 2015
cache2k, Java Caching, Turbo Charged, FOSDEM 2015
 
Brief introduction to kselftest
Brief introduction to kselftestBrief introduction to kselftest
Brief introduction to kselftest
 
Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)Analyzing Java Applications Using Thermostat (Omair Majid)
Analyzing Java Applications Using Thermostat (Omair Majid)
 

Viewers also liked

what kind of media institution might distribute your media product and why?
what kind of media institution might distribute your media product and why?what kind of media institution might distribute your media product and why?
what kind of media institution might distribute your media product and why?
furbymojo
 
Η Ρώμη - Η Αιώνια Πόλη
Η Ρώμη - Η Αιώνια ΠόληΗ Ρώμη - Η Αιώνια Πόλη
Η Ρώμη - Η Αιώνια Πόλη
angelosozil118
 

Viewers also liked (19)

Tech giants of the last decade
Tech giants of the last decadeTech giants of the last decade
Tech giants of the last decade
 
標準人壽My Smart Planner Android 應用程式 - 轉換投資選擇
標準人壽My Smart Planner Android 應用程式 - 轉換投資選擇標準人壽My Smart Planner Android 應用程式 - 轉換投資選擇
標準人壽My Smart Planner Android 應用程式 - 轉換投資選擇
 
標準人壽 iOS應用程式 - 轉換投資選擇
標準人壽 iOS應用程式 - 轉換投資選擇標準人壽 iOS應用程式 - 轉換投資選擇
標準人壽 iOS應用程式 - 轉換投資選擇
 
what kind of media institution might distribute your media product and why?
what kind of media institution might distribute your media product and why?what kind of media institution might distribute your media product and why?
what kind of media institution might distribute your media product and why?
 
Danielle hardin
Danielle hardinDanielle hardin
Danielle hardin
 
Frank Jermusek: 5 Useful Commerical Real Estate Tips
Frank Jermusek: 5 Useful Commerical Real Estate TipsFrank Jermusek: 5 Useful Commerical Real Estate Tips
Frank Jermusek: 5 Useful Commerical Real Estate Tips
 
Polish Stocks 6. January 2017
Polish Stocks 6. January 2017 Polish Stocks 6. January 2017
Polish Stocks 6. January 2017
 
Slideshare ps2
Slideshare ps2 Slideshare ps2
Slideshare ps2
 
Vocabulary movie stars
Vocabulary movie starsVocabulary movie stars
Vocabulary movie stars
 
baocao
baocaobaocao
baocao
 
IAB Native Advertising Playbook 12-04-2013
IAB Native Advertising Playbook 12-04-2013IAB Native Advertising Playbook 12-04-2013
IAB Native Advertising Playbook 12-04-2013
 
Kelompok 2 komite etik
Kelompok 2 komite etikKelompok 2 komite etik
Kelompok 2 komite etik
 
Final proposal pp
Final proposal ppFinal proposal pp
Final proposal pp
 
Magazine world is magnifique june 2014
Magazine world is magnifique june 2014Magazine world is magnifique june 2014
Magazine world is magnifique june 2014
 
Η Ρώμη - Η Αιώνια Πόλη
Η Ρώμη - Η Αιώνια ΠόληΗ Ρώμη - Η Αιώνια Πόλη
Η Ρώμη - Η Αιώνια Πόλη
 
Digital marketing lecture flow
Digital marketing lecture flowDigital marketing lecture flow
Digital marketing lecture flow
 
Digital marketing lecture flow
Digital marketing lecture flowDigital marketing lecture flow
Digital marketing lecture flow
 
CDP Supply-Chain-report-2015
CDP Supply-Chain-report-2015CDP Supply-Chain-report-2015
CDP Supply-Chain-report-2015
 
Sap basis slide . pp
Sap basis slide . ppSap basis slide . pp
Sap basis slide . pp
 

Similar to Js on-microcontrollers

SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
Chester Chen
 
20141111_SOS3_Gallo
20141111_SOS3_Gallo20141111_SOS3_Gallo
20141111_SOS3_Gallo
Andrea Gallo
 

Similar to Js on-microcontrollers (20)

Introduction to IoT.JS
Introduction to IoT.JSIntroduction to IoT.JS
Introduction to IoT.JS
 
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Things
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of ThingsJerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Things
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Things
 
Introduction to IoT.JS
Introduction to IoT.JSIntroduction to IoT.JS
Introduction to IoT.JS
 
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Thin...
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Thin...JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Thin...
JerryScript: An ultra-lighteweight JavaScript Engine for the Internet of Thin...
 
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
Вячеслав Блинов «Java Garbage Collection: A Performance Impact»
 
Deep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instancesDeep Dive on Amazon EC2 instances
Deep Dive on Amazon EC2 instances
 
Cat @ scale
Cat @ scaleCat @ scale
Cat @ scale
 
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
SF Big Analytics & SF Machine Learning Meetup: Machine Learning at the Limit ...
 
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
State of Java Elasticity. Tuning Java Efficiency - GIDS.JAVA LIVE 2020
 
Improving DragonFly's performance with PostgreSQL by Francois Tigeot
Improving DragonFly's performance with PostgreSQL by Francois TigeotImproving DragonFly's performance with PostgreSQL by Francois Tigeot
Improving DragonFly's performance with PostgreSQL by Francois Tigeot
 
20141111_SOS3_Gallo
20141111_SOS3_Gallo20141111_SOS3_Gallo
20141111_SOS3_Gallo
 
Big Lab Problems Solved with Spectrum Scale: Innovations for the Coral Program
Big Lab Problems Solved with Spectrum Scale: Innovations for the Coral ProgramBig Lab Problems Solved with Spectrum Scale: Innovations for the Coral Program
Big Lab Problems Solved with Spectrum Scale: Innovations for the Coral Program
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
Optimizing Servers for High-Throughput and Low-Latency at Dropbox
Optimizing Servers for High-Throughput and Low-Latency at DropboxOptimizing Servers for High-Throughput and Low-Latency at Dropbox
Optimizing Servers for High-Throughput and Low-Latency at Dropbox
 
Clang: More than just a C/C++ Compiler
Clang: More than just a C/C++ CompilerClang: More than just a C/C++ Compiler
Clang: More than just a C/C++ Compiler
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
SRV402 Deep Dive on Amazon EC2 Instances, Featuring Performance Optimization ...
 
Speedrunning the Open Street Map osm2pgsql Loader
Speedrunning the Open Street Map osm2pgsql LoaderSpeedrunning the Open Street Map osm2pgsql Loader
Speedrunning the Open Street Map osm2pgsql Loader
 
module01.ppt
module01.pptmodule01.ppt
module01.ppt
 
Computing Performance: On the Horizon (2021)
Computing Performance: On the Horizon (2021)Computing Performance: On the Horizon (2021)
Computing Performance: On the Horizon (2021)
 

Recently uploaded

Recently uploaded (20)

Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)Powerful Google developer tools for immediate impact! (2023-24 C)
Powerful Google developer tools for immediate impact! (2023-24 C)
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Tech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdfTech Trends Report 2024 Future Today Institute.pdf
Tech Trends Report 2024 Future Today Institute.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024Finology Group – Insurtech Innovation Award 2024
Finology Group – Insurtech Innovation Award 2024
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 

Js on-microcontrollers

  • 1. JavaScript on Microcontrollers Samsung Open Source Group 1 Tilmann Scheller LLVM Compiler Engineer t.scheller@samsung.com Samsung Open Source Group Samsung Research UK 2nd Samsung Web Tech Talk San Jose, USA, October 30, 2014
  • 2. Overview ● Introduction ● JavaScript engine code size ● JavaScript engine correctness/performance ● Summary Samsung Open Source Group 2
  • 3. Introduction Samsung Open Source Group 3
  • 4. Introduction ● Wearable devices becoming more and more widespread ● Weight and energy efficiency a big concern ● JavaScript very popular, easy to learn ● Scales from embedded to servers ● Execute JavaScript on a microcontroller! Samsung Open Source Group 4
  • 5. Target hardware ● Cortex-M3 microcontroller (32-bit ARM Thumb-2) ● 96KB of RAM ● 512KB of flash memory ● Clocked at 84MHz Samsung Open Source Group 5
  • 6. JS Engines ● Goal: JS engine which fits in the microcontroller constraints ● Option one: Pick an established JS engine and strip it down to fit on a microcontroller ● Option two: Pick a lightweight engine and make sure that it meets all the requirements Samsung Open Source Group 6
  • 7. JS Engines ● Two approaches pursued in parallel: – Try to minimize JavaScriptCore so that it fits on a microcontroller – Get the lightweight Duktape engine running on a microcontroller Samsung Open Source Group 7
  • 8. JavaScriptCore ● Well-established JS engine running on millions of devices ● High-performance (four distinct levels of optimization) ● Never intended to run in resource-constrained environments, primary focus is maximum performance ● Written in C++ Samsung Open Source Group 8
  • 9. Duktape ● Lightweight JS engine ● Focus on portability and a low footprint ● Written in C and about 40k lines of code (excluding comments) ● ECMAScript E5/E5.1 compliant ● Liberal license ● Active community, has been around for several years Samsung Open Source Group 9
  • 10. Code size Samsung Open Source Group 10
  • 11. JavaScriptCore minimization ● Challenge: JavaScriptCore was never intended for environments like this ● First attempt: – Took r170522 (June 26, 2014) of WebKit and built the EFL configuration for Thumb-2 ● Original (3.63 MB) ● Reduced (2.39 MB) ● Static (21.21 MB) – Several MB of heap memory consumed during runtime Samsung Open Source Group 11
  • 12. JavaScriptCore minimization ● Current snapshot: way too big! ● Second try: Use a snapshot from 2008 just before SquirrelFish was merged ● Performed minimizations: – Qt dependency was removed – Reduced the size of ICU data by disabling extra features – Rebuilt ICU with the –Os compiler option – Pthread was removed – Built older ICU libs – Stripped static JSC binary is now 1,647 KB (was: 19,578 KB) – The engine part of is 311 KB – The Unicode libraries are 562 Kbyte and the remaining size comes from libc, libm and libstdc++ libraries. Samsung Open Source Group 12
  • 13. JavaScriptCore minimization ● Engine size close to target size ● However, libraries rely on too many system calls to make it feasible to run on a baremetal system ● Too much effort to get JSC working on a baremetal system ● Aborting JSC investigation and directing all efforts towards Duktape Samsung Open Source Group 13
  • 14. Duktape ● Compiled for Thumb-2 ● Using the newlib C standard library ● No OS running on the microcontroller ● Statically linked binary ● C library has a big impact on the size of the executable ● Disabling certain optimizations (through preprocessor macros), helps to reduce code size even further Samsung Open Source Group 14
  • 15. Code size Static binary Engine Libraries 108 161 100 83 70 59 212 187 127 318 655 790 1207 311 0 200 400 600 800 1000 1200 1400 1600 1800 Samsung Open Source Group 15 1647 Duktape Thumb-2 baremetal noopt Duktape Thumb-2 baremetal Duktape ARM baremetal Duktape ARM Linux glibc JSC Thumb-2 Linux glibc KB Compiled at -Os ..., noopt = Duktape optimizations not compiled in, baremetal builds link against Newlib
  • 17. Correctness - test262 ● Duktape 0.12 and Arduino library 1.5.8, without DUK_OPT defines ● test262 (ECMAScript conformance test suite) results: – Ran 11824 tests ● Passed 11411 tests (96.5%) ● Failed 413 tests (3.5%) ● Failure details: – 144 tests ran out of memory – 10 tests timed out (300 secs) – 90 tests failed because of an undefined gettimeofday() function – 169 tests fail because of other reasons (have to be investigated) – Summary: 167 failures specific to the Arduino Due and 246 tests which fail on x86-64 as well Samsung Open Source Group 17
  • 18. test262 85 713 288957 Min Avg Max 350000 300000 250000 200000 150000 100000 50000 0 Execution time (ms) Samsung Open Source Group 18 Min Avg Max 80 70 60 50 40 30 20 10 0 54 57 75 Memory usage (KB)
  • 19. SunSpider ● Duktape 0.12 and Arduino library 1.5.8, without DUK_OPT defines ● Ran 26 tests – Passed 9 tests (34.6%) – Failed 17 tests (65.4%) ● Failure details: – 3 tests were too big (string-unpack-code.js (164K), string-tagcloud.js (172K), regexp-dna.js (400K)) – 13 tests run out of memory (3d-cube.js, 3d-morph.js, 3d-raytrace.js, access-binary-trees.js, access-nsieve.js, bitops-nsieve-bits.js, crypto-aes.js, crypto-md5.js, crypto-sha1.js, date-format-tofte.js, date-format-xparb.js, string-base64.js, string-validate-input.js) – 1 test failed because of undefined gettimeofday() function (math-cordic.js) Samsung Open Source Group 19
  • 20. SunSpider access-nbody 160 140 120 100 80 60 40 20 access-fannkuch bitops-bits-in-byte bitops-3bit-bits-in-byte controlflow-recursive bitops-bitwise-and math-partial-sums Samsung Open Source Group 20 math-spectral-norm string-fasta 0 149 41.5 64.3 74.8 140.2 25.9 62.3 21.8 119.9 54 64 50 49 50 70 51 53 57 Execution time (s) Memory usage (KB)
  • 21. Summary Samsung Open Source Group 21
  • 22. Summary ● JavaScriptCore proved to be unsuitable for microcontrollers ● Duktape fits well into flash and main memory ● Duktape has promising correctness results ● Ongoing effort to evaluate Duktape performance Samsung Open Source Group 22
  • 23. Thank you. Samsung Open Source Group 23
  • 24. We are hiring! Contact Information: Tilmann Scheller t.scheller@samsung.com Samsung Open Source Group Samsung Research UK Samsung Open Source Group 24