SlideShare a Scribd company logo
1 of 19
Download to read offline
Scratching the Itch 
How to attack slow applications, with particular reference 
to Scratch on a Raspberry Pi 
tim Rowledge 
tim@rowledge.org 
for the Raspberry Pi Foundation 
ESUG ’14 Cambridge UK 
Scratch lives at scratch.mit.edu - though be warned, the latest version is not Smalltalk based at all. 
Raspberry Pi lives at www.raspberrypi.org 
tim lives at www.rowledge.org/tim
“How many of you like the Ocean?” 
For the full musical experience of the following five slides, see the first 35 seconds of https://www.youtube.com/watch?v=hQeeQjdU2Bk And then enjoy 
the rest of Steam Powered Giraffe.
“It’s pretty wet, huh?”
“And how many of you like Fishing?”
“That’s right, nobody. 
Because it’s Boring”
“But how many of you like fighting 
Skeleton Pirates on the back of Killer Whales?” 
–Steam Powered Giraffe
Making code better is that exciting! 
• Scratch is an important application, perhaps the 
most used Smalltalk code out there 
• Raspberry Pi is wildly popular as an educational 
tool, a toy, a personal dynamic medium 
• Scratch is slow on a Pi :-( 
• We need to fix that. 
• Saddle up my Orca! 
Scratch on Pi has probably over a million regular users. That’s a scary large number of customers.
• Squeak… isn’t that some sort of old fashioned 
interpreted language? 
• Scratch is highly graphical, so it must be slow 
because of poor graphics in Squeak 
• Pi is ARM cpu based, so can’t possibly be fast 
• Pi is cheap… yada-yada
We all know what to do 
• Dream up some benchmarks 
• Run some tests 
• Do a few profiles 
• Fix problems 
• Profit!!!! 
This is what we normally do, or at least what we get told to do. Like most of what we are taught, there is a lot more to it.
Except… 
• Benchmarks are hard to devise 
• Tests don’t, often 
• Profiles only show where time is spent, not if it is 
spent wisely 
• Fix which problems? Code quality, algorithm 
choice, system design… 
Benchmarks are a morass of bad code, stupid ideas, inadequate thinking, simplistic approaches and general wrongness. And then we add all the numbers 
and pretend it means something. 
Tests can be worse.Even well thought out tests go out of date. 
Profiling is perhaps the most misunderstood issue of all.
Specifically… 
• Scratch/Pi was claimed to spend most time doing 
bitblt. Not actually true even for a totally graphical 
test. 
• Code to do a simple swap between two backgrounds 
involved many bitblts, mostly of ‘paint’ type. 
• Surrounding graphic ‘frame’ used several complex 
translucency bitblts for a virtually invisible effect 
• Multiple (ab)uses of #isKindOf:. Sigh.
• Actual bitblt time was 22% with a 6fps display rate 
• Pre-composite graphics to avoid multiple paint 
• Dump invisible prettiness 
• Avoid #isKindOf: 
• 10fps 
Here are some example changes made in the early part of the project.
BitBlt actually is slow on a Pi 
• The Pi SoC was originally intended for phones - essentially an iPhone 1 
logic board 
• Memory bandwidth to the ARM is not huge 
• We improved bitblt performance by a large factor with carefully written 
ARM assembler to replace some important routines; thanks to Ben Avison 
• Use ARM PLD instruction to preload scanlines 
• Make better use of ARM magic than C compiler can typically manage plus 
some SIMD trickery. 
• A lot of 1@1 sized blts; turned out to be a way of testing for A touching B. 
Replace with a very simple single-pixel test prim. Good case of a better 
algorithm rather than makee-faster 
The ARM bitblt improvements are in the trunk VM code, as is the pixel testing prim.
They did what? 
• Scratch uses an interesting and clever execution simulator to run the scripts; 
kind of a virtual machine running on the virtual machine. 
• Some really, really bad code in some important places. 
• #isKindOf: all over the place plus lots of state based behaviour instead of 
class based, thus wasting the benefits of the message sending VM. 
• Specialise some key parts of the Scratch engine to know what they do and 
some important sections run 8x faster. Suddenly Asteroids is playable. 
• Still a lot that could be done in this area 
• number/string conversion/polymorphism within Scratch costs a lot of time 
• still at least 50 extraneous #isKindOf: at last count 
Scratch’s execution mechanism is an excellent example of a very clever idea that didn't get looked after as well as it deserved. We’re trying to fix that.
Script Editing 
• Users drag script elements from palette to editor and around editor to build 
and change a script 
• Dragging a large stack of script blocks involves creating a large bitmap, 
rendering all the blocks into it and then animating dragging a mostly 
transparent bitmap. 
• Added caching of the fiddly bits, rounded or <> ends of argument morphs to 
speed up this rendering 
• In many cases it’s almost as fast to (re)draw each script block individually at 
each step to save so much transparency work. 
• Perhaps we will change to dragging a symbolic script chunk 
• Changes in place improved the system from ‘unusable by my students’ to 
‘wow, amazing’
Moving to a modern image 
• Scratch was originally written in a 2.4 era image and much 
hacking was done 
• Lots has changed 
• importantly the old image could not run on latest VMs 
• StackVM as a first step; major work 
• Required extracting code from old system, porting 
forward to 4.5 image 
• Oh my - look at the list -> 
This is what happens when code gets left to mould. It becomes a major effort to bring it back to a modern world.
• Huge changes to Morph 
• Changes to event handling - #mouseDown: etc 
• Scratch relies upon recorded keyboard/mouse state as well as event changes 
• Rewrote (with much help from Nic Cellier) the core text scanning to remove 
pointless duplication and speed up quite a bit 
• #copy-ing chaos 
• Custom i18n solution 
• Message name clashes as facilities added to general Morph that were Scratch 
specific 
• Morphic layout changes 
• Morphic drag/drop infrastructure 
• Dictionary>>do: changed semantics! 
And here is a list of at least some of the problem areas that have been tackled.
Going Faster 
• NuScratch beta is now near final and runs on the StackVM 
• Next step is CogVM/ARMv6 
• Eliot is freakin’ amazing 
• Tantalisingly close to running in simulator 
• Huge amount of subtle tricky stuff 
• Sends, SICs, PICs and most returns done 
• One day, ARMv8
Where can I get this wonderful stuff? 
• Beta release for ARM is on 
• http://github.com/raspberrypi/scratch 
• Beta8 tgz is latest 
• extract the image and run on OS X, Win-whatever, 
other linuxen. 
• Feedback!

More Related Content

What's hot

Porque Odeio Branches
Porque Odeio BranchesPorque Odeio Branches
Porque Odeio BranchesRafael Petry
 
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) -
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) - Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) -
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) - Puppet
 
Amsterdam Meetup Presentation - Marts 2014
Amsterdam Meetup Presentation - Marts 2014Amsterdam Meetup Presentation - Marts 2014
Amsterdam Meetup Presentation - Marts 2014Mads Møller
 
React, London JS Meetup, 11 Aug 2015
React, London JS Meetup, 11 Aug 2015React, London JS Meetup, 11 Aug 2015
React, London JS Meetup, 11 Aug 2015Stuart Harris
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp KeynoteYehuda Katz
 
Multimedia Buzzword Bingo: Translating to English
 Multimedia Buzzword Bingo: Translating to English Multimedia Buzzword Bingo: Translating to English
Multimedia Buzzword Bingo: Translating to EnglishDerek Buitenhuis
 
Trunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsTrunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsPerforce
 

What's hot (11)

Porque Odeio Branches
Porque Odeio BranchesPorque Odeio Branches
Porque Odeio Branches
 
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) -
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) - Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) -
Puppet Camp Atlanta 2014: DEV Toolsets for Ops (Beginner) -
 
Amsterdam Meetup Presentation - Marts 2014
Amsterdam Meetup Presentation - Marts 2014Amsterdam Meetup Presentation - Marts 2014
Amsterdam Meetup Presentation - Marts 2014
 
Opening up Open Source
Opening up Open SourceOpening up Open Source
Opening up Open Source
 
.NET, Alexa and me
.NET, Alexa and me.NET, Alexa and me
.NET, Alexa and me
 
React, London JS Meetup, 11 Aug 2015
React, London JS Meetup, 11 Aug 2015React, London JS Meetup, 11 Aug 2015
React, London JS Meetup, 11 Aug 2015
 
Merb Camp Keynote
Merb Camp KeynoteMerb Camp Keynote
Merb Camp Keynote
 
Multimedia Buzzword Bingo: Translating to English
 Multimedia Buzzword Bingo: Translating to English Multimedia Buzzword Bingo: Translating to English
Multimedia Buzzword Bingo: Translating to English
 
Stackato v6
Stackato v6Stackato v6
Stackato v6
 
ZN-2015
ZN-2015ZN-2015
ZN-2015
 
Trunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and EconomicsTrunk Based Development in the Enterprise - Its Relevance and Economics
Trunk Based Development in the Enterprise - Its Relevance and Economics
 

Similar to Scratching the itch, making Scratch for the Raspberry Pie

Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Pythoninfodox
 
Vulnerability, exploit to metasploit
Vulnerability, exploit to metasploitVulnerability, exploit to metasploit
Vulnerability, exploit to metasploitTiago Henriques
 
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di PriscoFwdays
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talkReuven Lerner
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UKRicard Clau
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkTomas Doran
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming LanguageJaeju Kim
 
Ruby codebases in an entropic universe
Ruby codebases in an entropic universeRuby codebases in an entropic universe
Ruby codebases in an entropic universeNiranjan Paranjape
 
Rapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The WebRapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The WebPINT Inc
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Fwdays
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....Mike Harris
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_monTomas Doran
 
Raspberry pi overview
Raspberry pi overview Raspberry pi overview
Raspberry pi overview Matthew Karas
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pieTomas Doran
 

Similar to Scratching the itch, making Scratch for the Raspberry Pie (20)

Steelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with PythonSteelcon 2014 - Process Injection with Python
Steelcon 2014 - Process Injection with Python
 
Gpgpu intro
Gpgpu introGpgpu intro
Gpgpu intro
 
Vulnerability, exploit to metasploit
Vulnerability, exploit to metasploitVulnerability, exploit to metasploit
Vulnerability, exploit to metasploit
 
Test
TestTest
Test
 
Software + Babies
Software + BabiesSoftware + Babies
Software + Babies
 
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco"Leveraging the Event Loop for Blazing-Fast Applications!",  Michael Di Prisco
"Leveraging the Event Loop for Blazing-Fast Applications!", Michael Di Prisco
 
Rails development environment talk
Rails development environment talkRails development environment talk
Rails development environment talk
 
cadec-2017-golang
cadec-2017-golangcadec-2017-golang
cadec-2017-golang
 
Scaling with Symfony - PHP UK
Scaling with Symfony - PHP UKScaling with Symfony - PHP UK
Scaling with Symfony - PHP UK
 
Messaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new frameworkMessaging, interoperability and log aggregation - a new framework
Messaging, interoperability and log aggregation - a new framework
 
From Web to Mobile with Stage 3D
From Web to Mobile with Stage 3DFrom Web to Mobile with Stage 3D
From Web to Mobile with Stage 3D
 
Rust Programming Language
Rust Programming LanguageRust Programming Language
Rust Programming Language
 
Ruby codebases in an entropic universe
Ruby codebases in an entropic universeRuby codebases in an entropic universe
Ruby codebases in an entropic universe
 
Rapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The WebRapid Evolution of Web Dev? aka Talking About The Web
Rapid Evolution of Web Dev? aka Talking About The Web
 
Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"Игорь Фесенко "Direction of C# as a High-Performance Language"
Игорь Фесенко "Direction of C# as a High-Performance Language"
 
JRuby: The Hard Parts
JRuby: The Hard PartsJRuby: The Hard Parts
JRuby: The Hard Parts
 
How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....How I Learned to Stop Worrying and Love Legacy Code.....
How I Learned to Stop Worrying and Love Legacy Code.....
 
Real time system_performance_mon
Real time system_performance_monReal time system_performance_mon
Real time system_performance_mon
 
Raspberry pi overview
Raspberry pi overview Raspberry pi overview
Raspberry pi overview
 
Cooking a rabbit pie
Cooking a rabbit pieCooking a rabbit pie
Cooking a rabbit pie
 

More from ESUG

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingESUG
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in PharoESUG
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapESUG
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoESUG
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...ESUG
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsESUG
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6ESUG
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationESUG
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingESUG
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesESUG
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportESUG
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsESUG
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector TuningESUG
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseESUG
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FutureESUG
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the DebuggerESUG
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing ScoreESUG
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptESUG
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocESUG
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsESUG
 

More from ESUG (20)

Workshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programmingWorkshop: Identifying concept inventories in agile programming
Workshop: Identifying concept inventories in agile programming
 
Technical documentation support in Pharo
Technical documentation support in PharoTechnical documentation support in Pharo
Technical documentation support in Pharo
 
The Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and RoadmapThe Pharo Debugger and Debugging tools: Advances and Roadmap
The Pharo Debugger and Debugging tools: Advances and Roadmap
 
Sequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in PharoSequence: Pipeline modelling in Pharo
Sequence: Pipeline modelling in Pharo
 
Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...Migration process from monolithic to micro frontend architecture in mobile ap...
Migration process from monolithic to micro frontend architecture in mobile ap...
 
Analyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early resultsAnalyzing Dart Language with Pharo: Report and early results
Analyzing Dart Language with Pharo: Report and early results
 
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
Transpiling Pharo Classes to JS ECMAScript 5 versus ECMAScript 6
 
A Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test GenerationA Unit Test Metamodel for Test Generation
A Unit Test Metamodel for Test Generation
 
Creating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic ProgrammingCreating Unit Tests Using Genetic Programming
Creating Unit Tests Using Genetic Programming
 
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution ModesThreaded-Execution and CPS Provide Smooth Switching Between Execution Modes
Threaded-Execution and CPS Provide Smooth Switching Between Execution Modes
 
Exploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience ReportExploring GitHub Actions through EGAD: An Experience Report
Exploring GitHub Actions through EGAD: An Experience Report
 
Pharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIsPharo: a reflective language A first systematic analysis of reflective APIs
Pharo: a reflective language A first systematic analysis of reflective APIs
 
Garbage Collector Tuning
Garbage Collector TuningGarbage Collector Tuning
Garbage Collector Tuning
 
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame CaseImproving Performance Through Object Lifetime Profiling: the DataFrame Case
Improving Performance Through Object Lifetime Profiling: the DataFrame Case
 
Pharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and FuturePharo DataFrame: Past, Present, and Future
Pharo DataFrame: Past, Present, and Future
 
thisContext in the Debugger
thisContext in the DebuggerthisContext in the Debugger
thisContext in the Debugger
 
Websockets for Fencing Score
Websockets for Fencing ScoreWebsockets for Fencing Score
Websockets for Fencing Score
 
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScriptShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
ShowUs: PharoJS.org Develop in Pharo, Run on JavaScript
 
Advanced Object- Oriented Design Mooc
Advanced Object- Oriented Design MoocAdvanced Object- Oriented Design Mooc
Advanced Object- Oriented Design Mooc
 
A New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and TransformationsA New Architecture Reconciling Refactorings and Transformations
A New Architecture Reconciling Refactorings and Transformations
 

Recently uploaded

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identityteam-WIBU
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtimeandrehoraa
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...Akihiro Suda
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfStefano Stabellini
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfDrew Moseley
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...OnePlan Solutions
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Developmentvyaparkranti
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsAhmed Mohamed
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfMarharyta Nedzelska
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Cizo Technology Services
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceBrainSell Technologies
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprisepreethippts
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Hr365.us smith
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringHironori Washizaki
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Mater
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalLionel Briand
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfYashikaSharma391629
 

Recently uploaded (20)

Post Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on IdentityPost Quantum Cryptography – The Impact on Identity
Post Quantum Cryptography – The Impact on Identity
 
SpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at RuntimeSpotFlow: Tracking Method Calls and States at Runtime
SpotFlow: Tracking Method Calls and States at Runtime
 
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
20240415 [Container Plumbing Days] Usernetes Gen2 - Kubernetes in Rootless Do...
 
Xen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdfXen Safety Embedded OSS Summit April 2024 v4.pdf
Xen Safety Embedded OSS Summit April 2024 v4.pdf
 
Comparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdfComparing Linux OS Image Update Models - EOSS 2024.pdf
Comparing Linux OS Image Update Models - EOSS 2024.pdf
 
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
Maximizing Efficiency and Profitability with OnePlan’s Professional Service A...
 
VK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web DevelopmentVK Business Profile - provides IT solutions and Web Development
VK Business Profile - provides IT solutions and Web Development
 
Unveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML DiagramsUnveiling Design Patterns: A Visual Guide with UML Diagrams
Unveiling Design Patterns: A Visual Guide with UML Diagrams
 
A healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdfA healthy diet for your Java application Devoxx France.pdf
A healthy diet for your Java application Devoxx France.pdf
 
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
Global Identity Enrolment and Verification Pro Solution - Cizo Technology Ser...
 
CRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. SalesforceCRM Contender Series: HubSpot vs. Salesforce
CRM Contender Series: HubSpot vs. Salesforce
 
Odoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 EnterpriseOdoo 14 - eLearning Module In Odoo 14 Enterprise
Odoo 14 - eLearning Module In Odoo 14 Enterprise
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)Recruitment Management Software Benefits (Infographic)
Recruitment Management Software Benefits (Infographic)
 
Machine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their EngineeringMachine Learning Software Engineering Patterns and Their Engineering
Machine Learning Software Engineering Patterns and Their Engineering
 
Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)Ahmed Motair CV April 2024 (Senior SW Developer)
Ahmed Motair CV April 2024 (Senior SW Developer)
 
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Precise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive GoalPrecise and Complete Requirements? An Elusive Goal
Precise and Complete Requirements? An Elusive Goal
 
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdfInnovate and Collaborate- Harnessing the Power of Open Source Software.pdf
Innovate and Collaborate- Harnessing the Power of Open Source Software.pdf
 

Scratching the itch, making Scratch for the Raspberry Pie

  • 1. Scratching the Itch How to attack slow applications, with particular reference to Scratch on a Raspberry Pi tim Rowledge tim@rowledge.org for the Raspberry Pi Foundation ESUG ’14 Cambridge UK Scratch lives at scratch.mit.edu - though be warned, the latest version is not Smalltalk based at all. Raspberry Pi lives at www.raspberrypi.org tim lives at www.rowledge.org/tim
  • 2. “How many of you like the Ocean?” For the full musical experience of the following five slides, see the first 35 seconds of https://www.youtube.com/watch?v=hQeeQjdU2Bk And then enjoy the rest of Steam Powered Giraffe.
  • 4. “And how many of you like Fishing?”
  • 5. “That’s right, nobody. Because it’s Boring”
  • 6. “But how many of you like fighting Skeleton Pirates on the back of Killer Whales?” –Steam Powered Giraffe
  • 7. Making code better is that exciting! • Scratch is an important application, perhaps the most used Smalltalk code out there • Raspberry Pi is wildly popular as an educational tool, a toy, a personal dynamic medium • Scratch is slow on a Pi :-( • We need to fix that. • Saddle up my Orca! Scratch on Pi has probably over a million regular users. That’s a scary large number of customers.
  • 8. • Squeak… isn’t that some sort of old fashioned interpreted language? • Scratch is highly graphical, so it must be slow because of poor graphics in Squeak • Pi is ARM cpu based, so can’t possibly be fast • Pi is cheap… yada-yada
  • 9. We all know what to do • Dream up some benchmarks • Run some tests • Do a few profiles • Fix problems • Profit!!!! This is what we normally do, or at least what we get told to do. Like most of what we are taught, there is a lot more to it.
  • 10. Except… • Benchmarks are hard to devise • Tests don’t, often • Profiles only show where time is spent, not if it is spent wisely • Fix which problems? Code quality, algorithm choice, system design… Benchmarks are a morass of bad code, stupid ideas, inadequate thinking, simplistic approaches and general wrongness. And then we add all the numbers and pretend it means something. Tests can be worse.Even well thought out tests go out of date. Profiling is perhaps the most misunderstood issue of all.
  • 11. Specifically… • Scratch/Pi was claimed to spend most time doing bitblt. Not actually true even for a totally graphical test. • Code to do a simple swap between two backgrounds involved many bitblts, mostly of ‘paint’ type. • Surrounding graphic ‘frame’ used several complex translucency bitblts for a virtually invisible effect • Multiple (ab)uses of #isKindOf:. Sigh.
  • 12. • Actual bitblt time was 22% with a 6fps display rate • Pre-composite graphics to avoid multiple paint • Dump invisible prettiness • Avoid #isKindOf: • 10fps Here are some example changes made in the early part of the project.
  • 13. BitBlt actually is slow on a Pi • The Pi SoC was originally intended for phones - essentially an iPhone 1 logic board • Memory bandwidth to the ARM is not huge • We improved bitblt performance by a large factor with carefully written ARM assembler to replace some important routines; thanks to Ben Avison • Use ARM PLD instruction to preload scanlines • Make better use of ARM magic than C compiler can typically manage plus some SIMD trickery. • A lot of 1@1 sized blts; turned out to be a way of testing for A touching B. Replace with a very simple single-pixel test prim. Good case of a better algorithm rather than makee-faster The ARM bitblt improvements are in the trunk VM code, as is the pixel testing prim.
  • 14. They did what? • Scratch uses an interesting and clever execution simulator to run the scripts; kind of a virtual machine running on the virtual machine. • Some really, really bad code in some important places. • #isKindOf: all over the place plus lots of state based behaviour instead of class based, thus wasting the benefits of the message sending VM. • Specialise some key parts of the Scratch engine to know what they do and some important sections run 8x faster. Suddenly Asteroids is playable. • Still a lot that could be done in this area • number/string conversion/polymorphism within Scratch costs a lot of time • still at least 50 extraneous #isKindOf: at last count Scratch’s execution mechanism is an excellent example of a very clever idea that didn't get looked after as well as it deserved. We’re trying to fix that.
  • 15. Script Editing • Users drag script elements from palette to editor and around editor to build and change a script • Dragging a large stack of script blocks involves creating a large bitmap, rendering all the blocks into it and then animating dragging a mostly transparent bitmap. • Added caching of the fiddly bits, rounded or <> ends of argument morphs to speed up this rendering • In many cases it’s almost as fast to (re)draw each script block individually at each step to save so much transparency work. • Perhaps we will change to dragging a symbolic script chunk • Changes in place improved the system from ‘unusable by my students’ to ‘wow, amazing’
  • 16. Moving to a modern image • Scratch was originally written in a 2.4 era image and much hacking was done • Lots has changed • importantly the old image could not run on latest VMs • StackVM as a first step; major work • Required extracting code from old system, porting forward to 4.5 image • Oh my - look at the list -> This is what happens when code gets left to mould. It becomes a major effort to bring it back to a modern world.
  • 17. • Huge changes to Morph • Changes to event handling - #mouseDown: etc • Scratch relies upon recorded keyboard/mouse state as well as event changes • Rewrote (with much help from Nic Cellier) the core text scanning to remove pointless duplication and speed up quite a bit • #copy-ing chaos • Custom i18n solution • Message name clashes as facilities added to general Morph that were Scratch specific • Morphic layout changes • Morphic drag/drop infrastructure • Dictionary>>do: changed semantics! And here is a list of at least some of the problem areas that have been tackled.
  • 18. Going Faster • NuScratch beta is now near final and runs on the StackVM • Next step is CogVM/ARMv6 • Eliot is freakin’ amazing • Tantalisingly close to running in simulator • Huge amount of subtle tricky stuff • Sends, SICs, PICs and most returns done • One day, ARMv8
  • 19. Where can I get this wonderful stuff? • Beta release for ARM is on • http://github.com/raspberrypi/scratch • Beta8 tgz is latest • extract the image and run on OS X, Win-whatever, other linuxen. • Feedback!