SlideShare ist ein Scribd-Unternehmen logo
1 von 22
Downloaden Sie, um offline zu lesen
Old Dog, New Tricks
A Schemer’s Guide to JavaScript
Implementations
Quasiconf 2012
Andy Wingo
wingo@igalia.com
Compiler hacker at Igalia
Contract work on language implementations
V8, JavaScriptCore
Schemer
Scheme in one slide
Parse.
Expand.
Optimize.
Codegen.
Run.
JavaScript in one slide
Pre-parse.
Run.
Parse.
Codegen.
Run.
Optimize.
Codegen.
Run.
...
On optimization
Proof-driven program transformation
Scheme: Static proofs derived from
interprocedural flow analysis
JS: Dynamic proofs based on run-time
observations, with ability to invalidate
transformations if assumptions fail to hold
Barriers to optimization in
Scheme
Mutable toplevels
Separate compilation
Incomplete type information
No information on what to inline
call/cc
None of these inhibit
JavaScript
Assume toplevels are immutable
No real separate compilation
A wealth of type information
Dynamic profiling identifies inline candidates
No call/cc
“Adaptive optimization”
Types and hot spots not known until runtime
Types and hot spots can change over time
Assumptions can be invalidated over time
Adaptive optimization: speculative optimization
with bailout
Deoptimization for debugging
Allow multi-leveled inlining and code motion
while preserving programmer’s mental model of
how evaluation works
Deoptimization already required by speculation
failures
Other common JS
optimizations
Unboxing
Common subexpression elimination
Loop invariant code motion (or loop peeling +
CSE)
Range inference
Register allocation
Block reordering (?)
But to be clear: dynamic inlining is the big one
Different deployment models
Scheme implementations rarely run attacker- controlled code
JS: Constant blinding to prevent vulnerabilities
in non-JS code from using JS as a heap-spray
No threads in JS
Representation hacks
JS: NaN-boxing, sometimes
Rope strings
Dedicated regexp compilers
Matching word-at-a-time, hard to beat with a
general compiler
Lazy tear-off in JSC
A static scope implementation trick
Implementing static scope
Chains: Activations on heap (!)
❧ Closure creation: O(1) space and time
❧ Free var access: O(n) time
❧ Not “safe for space”
Displays: Activations on stack
❧ Closure creation: O(n) space and time
❧ Free var access: O(1) time
❧ Mutated variables usually boxed
Lazy tear-off in JavaScriptCore
Activations on stack
Only allocate scope chain node if closure is
captured
When control leaves function, tear off stack to
heap, relocating pointer in scope node (no
threads in JS)
Memory advantages of chains with stack
discipline of display closures
Free var access still O(n) but inlinable
Living with eval
Eval only evil if it defines new locals
var foo = 10;
function f(s){ eval(s); return foo; }
f('var foo=20;') ⇒ 20

Otherwise great: a compiler available to the user
Functions in which eval appears not fully
optimizable: must expose symbol tables
Inline caches
Per-caller memoization, in code
Fundamental optimization for property access
Not as needed in Scheme because not much
polymorphism
Can allow efficient generic arithmetic
Can make CLOS-style generics more efficient
Clojure-like sequence protocols
Function application?
Dealing with the devil
Runtime codegen in JS has a price: C++
Most Scheme implementations are self-hosted,
with AOT compiler already
Challenge: add adaptive optimization to existing
Scheme implementation
Requires good AOT compiler!
JS can change the way we code
Scheme’s static implementations encourage
static programming
define-integrable
(declare (type fixnum x))
(declare (safety 0) (speed 3))
(declare (usual-integrations))
include instead of load

Adaptive optimization can bring back
dynamicity
Summary
In Smart vs Lazy, Schemers always chose Smart
A bit of laziness won’t hurt
Adaptive optimization in Scheme!
questions?
❧ Work: http://www.igalia.com/compilers
❧ Words: http://wingolog.org/
❧ Slides: http://wingolog.org/pub/qc-2012js-slides.pdf

❧ Notes: http://wingolog.org/pub/qc-2012js-notes.pdf

Weitere ähnliche Inhalte

Was ist angesagt?

Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
lennartkats
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
lennartkats
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
Jerry Chou
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
lennartkats
 

Was ist angesagt? (18)

Eclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JITEclipse Day India 2015 - Java bytecode analysis and JIT
Eclipse Day India 2015 - Java bytecode analysis and JIT
 
Javascript internals
Javascript internalsJavascript internals
Javascript internals
 
Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)Remix Your Language Tooling (JSConf.eu 2012)
Remix Your Language Tooling (JSConf.eu 2012)
 
Reactive Extensions for JavaScript
Reactive Extensions for JavaScriptReactive Extensions for JavaScript
Reactive Extensions for JavaScript
 
On component interface
On component interfaceOn component interface
On component interface
 
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
Integrated Language Definition Testing: Enabling Test-Driven Language Develop...
 
Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)Using Aspects for Language Portability (SCAM 2010)
Using Aspects for Language Portability (SCAM 2010)
 
The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)The Spoofax Language Workbench (SPLASH 2010)
The Spoofax Language Workbench (SPLASH 2010)
 
Language Engineering in the Cloud
Language Engineering in the CloudLanguage Engineering in the Cloud
Language Engineering in the Cloud
 
2nd presantation
2nd presantation2nd presantation
2nd presantation
 
A simple tool for debug (tap>)
A simple tool for debug (tap>)A simple tool for debug (tap>)
A simple tool for debug (tap>)
 
Intro dotnet
Intro dotnetIntro dotnet
Intro dotnet
 
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
ITB2019 Real World Scenarios for Modern CFML - Nolan ErckITB2019 Real World Scenarios for Modern CFML - Nolan Erck
ITB2019 Real World Scenarios for Modern CFML - Nolan Erck
 
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
[PyCon 2014 APAC] How to integrate python into a scala stack to build realtim...
 
C++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variablesC++ Tail Recursion Using 64-bit variables
C++ Tail Recursion Using 64-bit variables
 
Test-driven language development
Test-driven language developmentTest-driven language development
Test-driven language development
 
At Last an OCL Debugger
At Last an OCL DebuggerAt Last an OCL Debugger
At Last an OCL Debugger
 
C-Sharp 6.0 ver2
C-Sharp 6.0 ver2C-Sharp 6.0 ver2
C-Sharp 6.0 ver2
 

Andere mochten auch

Andere mochten auch (6)

State of the kit (FOSDEM 2013)
State of the kit (FOSDEM 2013)State of the kit (FOSDEM 2013)
State of the kit (FOSDEM 2013)
 
JavaScriptCore's DFG JIT (JSConf EU 2012)
JavaScriptCore's DFG JIT (JSConf EU 2012)JavaScriptCore's DFG JIT (JSConf EU 2012)
JavaScriptCore's DFG JIT (JSConf EU 2012)
 
Hybrid mobile apps
Hybrid mobile appsHybrid mobile apps
Hybrid mobile apps
 
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
Knit, Chisel, Hack: Building Programs in Guile Scheme (Strange Loop 2016)
 
Intervalos.números.reais
Intervalos.números.reaisIntervalos.números.reais
Intervalos.números.reais
 
Extreme JavaScript Performance
Extreme JavaScript PerformanceExtreme JavaScript Performance
Extreme JavaScript Performance
 

Ähnlich wie Partial Continuations, Lessons From JavaScript and Guile in 2012 (Quasiconf 2012)

Technology Stack Discussion
Technology Stack DiscussionTechnology Stack Discussion
Technology Stack Discussion
Zaiyang Li
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
YLTO
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
JAX London
 

Ähnlich wie Partial Continuations, Lessons From JavaScript and Guile in 2012 (Quasiconf 2012) (20)

Develop realtime web with Scala and Xitrum
Develop realtime web with Scala and XitrumDevelop realtime web with Scala and Xitrum
Develop realtime web with Scala and Xitrum
 
Whats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ DevelopersWhats New in Visual Studio 2012 for C++ Developers
Whats New in Visual Studio 2012 for C++ Developers
 
Panama.pdf
Panama.pdfPanama.pdf
Panama.pdf
 
Peyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_futurePeyton jones-2011-parallel haskell-the_future
Peyton jones-2011-parallel haskell-the_future
 
Simon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelismSimon Peyton Jones: Managing parallelism
Simon Peyton Jones: Managing parallelism
 
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin NakovJava 7 - New Features - by Mihail Stoynov and Svetlin Nakov
Java 7 - New Features - by Mihail Stoynov and Svetlin Nakov
 
Technology Stack Discussion
Technology Stack DiscussionTechnology Stack Discussion
Technology Stack Discussion
 
The Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compilerThe Parenscript Common Lisp to JavaScript compiler
The Parenscript Common Lisp to JavaScript compiler
 
Future Programming Language
Future Programming LanguageFuture Programming Language
Future Programming Language
 
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor BuzatovićJavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
JavaCro'14 - Is there Kotlin after Java 8 – Ivan Turčinović and Igor Buzatović
 
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
Alberto Maria Angelo Paro - Isomorphic programming in Scala and WebDevelopmen...
 
Rethinking the debugger
Rethinking the debuggerRethinking the debugger
Rethinking the debugger
 
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
차세대컴파일러, VM의미래: 애플 오픈소스 LLVM
 
Graph ql subscriptions through the looking glass
Graph ql subscriptions through the looking glassGraph ql subscriptions through the looking glass
Graph ql subscriptions through the looking glass
 
Framework engineering JCO 2011
Framework engineering JCO 2011Framework engineering JCO 2011
Framework engineering JCO 2011
 
Alberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.jsAlberto Paro - Hands on Scala.js
Alberto Paro - Hands on Scala.js
 
Scala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJSScala Italy 2015 - Hands On ScalaJS
Scala Italy 2015 - Hands On ScalaJS
 
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben EvansJava Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
Java Core | Modern Java Concurrency | Martijn Verburg & Ben Evans
 
Migration Spring PetClinic to Quarkus
Migration Spring PetClinic to QuarkusMigration Spring PetClinic to Quarkus
Migration Spring PetClinic to Quarkus
 
node.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoonnode.js 실무 - node js in practice by Jesang Yoon
node.js 실무 - node js in practice by Jesang Yoon
 

Mehr von Igalia

Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
Igalia
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
Igalia
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
Igalia
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Igalia
 

Mehr von Igalia (20)

A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?A Year of the Servo Reboot: Where Are We Now?
A Year of the Servo Reboot: Where Are We Now?
 
Building End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPEBuilding End-user Applications on Embedded Devices with WPE
Building End-user Applications on Embedded Devices with WPE
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
Automated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded DevicesAutomated Testing for Web-based Systems on Embedded Devices
Automated Testing for Web-based Systems on Embedded Devices
 
Embedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to MaintenanceEmbedding WPE WebKit - from Bring-up to Maintenance
Embedding WPE WebKit - from Bring-up to Maintenance
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdf
 
Running JS via WASM faster with JIT
Running JS via WASM      faster with JITRunning JS via WASM      faster with JIT
Running JS via WASM faster with JIT
 
To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!To crash or not to crash: if you do, at least recover fast!
To crash or not to crash: if you do, at least recover fast!
 
Implementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamerImplementing a Vulkan Video Encoder From Mesa to GStreamer
Implementing a Vulkan Video Encoder From Mesa to GStreamer
 
8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa8 Years of Open Drivers, including the State of Vulkan in Mesa
8 Years of Open Drivers, including the State of Vulkan in Mesa
 
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por IgaliaIntroducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
Introducción a Mesa. Caso específico dos dispositivos Raspberry Pi por Igalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera Linux
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVM
 
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUsturnip: Update on Open Source Vulkan Driver for Adreno GPUs
turnip: Update on Open Source Vulkan Driver for Adreno GPUs
 
Graphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devicesGraphics stack updates for Raspberry Pi devices
Graphics stack updates for Raspberry Pi devices
 
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOSDelegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
Delegated Compositing - Utilizing Wayland Protocols for Chromium on ChromeOS
 
MessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the webMessageFormat: The future of i18n on the web
MessageFormat: The future of i18n on the web
 
Replacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shadersReplacing the geometry pipeline with mesh shaders
Replacing the geometry pipeline with mesh shaders
 
I'm not an AMD expert, but...
I'm not an AMD expert, but...I'm not an AMD expert, but...
I'm not an AMD expert, but...
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on Raspberry
 

Kürzlich hochgeladen

Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Safe Software
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 

Kürzlich hochgeladen (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers:  A Deep Dive into Serverless Spatial Data and FMECloud Frontiers:  A Deep Dive into Serverless Spatial Data and FME
Cloud Frontiers: A Deep Dive into Serverless Spatial Data and FME
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
Apidays New York 2024 - APIs in 2030: The Risk of Technological Sleepwalk by ...
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
Apidays New York 2024 - Passkeys: Developing APIs to enable passwordless auth...
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)Introduction to Multilingual Retrieval Augmented Generation (RAG)
Introduction to Multilingual Retrieval Augmented Generation (RAG)
 
[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf[BuildWithAI] Introduction to Gemini.pdf
[BuildWithAI] Introduction to Gemini.pdf
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 

Partial Continuations, Lessons From JavaScript and Guile in 2012 (Quasiconf 2012)

  • 1. Old Dog, New Tricks A Schemer’s Guide to JavaScript Implementations Quasiconf 2012 Andy Wingo
  • 2. wingo@igalia.com Compiler hacker at Igalia Contract work on language implementations V8, JavaScriptCore Schemer
  • 3. Scheme in one slide Parse. Expand. Optimize. Codegen. Run.
  • 4. JavaScript in one slide Pre-parse. Run. Parse. Codegen. Run. Optimize. Codegen. Run. ...
  • 5. On optimization Proof-driven program transformation Scheme: Static proofs derived from interprocedural flow analysis JS: Dynamic proofs based on run-time observations, with ability to invalidate transformations if assumptions fail to hold
  • 6. Barriers to optimization in Scheme Mutable toplevels Separate compilation Incomplete type information No information on what to inline call/cc
  • 7. None of these inhibit JavaScript Assume toplevels are immutable No real separate compilation A wealth of type information Dynamic profiling identifies inline candidates No call/cc
  • 8. “Adaptive optimization” Types and hot spots not known until runtime Types and hot spots can change over time Assumptions can be invalidated over time Adaptive optimization: speculative optimization with bailout
  • 9. Deoptimization for debugging Allow multi-leveled inlining and code motion while preserving programmer’s mental model of how evaluation works Deoptimization already required by speculation failures
  • 10. Other common JS optimizations Unboxing Common subexpression elimination Loop invariant code motion (or loop peeling + CSE) Range inference Register allocation Block reordering (?) But to be clear: dynamic inlining is the big one
  • 11. Different deployment models Scheme implementations rarely run attacker- controlled code JS: Constant blinding to prevent vulnerabilities in non-JS code from using JS as a heap-spray No threads in JS
  • 12. Representation hacks JS: NaN-boxing, sometimes Rope strings
  • 13. Dedicated regexp compilers Matching word-at-a-time, hard to beat with a general compiler
  • 14. Lazy tear-off in JSC A static scope implementation trick
  • 15. Implementing static scope Chains: Activations on heap (!) ❧ Closure creation: O(1) space and time ❧ Free var access: O(n) time ❧ Not “safe for space” Displays: Activations on stack ❧ Closure creation: O(n) space and time ❧ Free var access: O(1) time ❧ Mutated variables usually boxed
  • 16. Lazy tear-off in JavaScriptCore Activations on stack Only allocate scope chain node if closure is captured When control leaves function, tear off stack to heap, relocating pointer in scope node (no threads in JS) Memory advantages of chains with stack discipline of display closures Free var access still O(n) but inlinable
  • 17. Living with eval Eval only evil if it defines new locals var foo = 10; function f(s){ eval(s); return foo; } f('var foo=20;') ⇒ 20 Otherwise great: a compiler available to the user Functions in which eval appears not fully optimizable: must expose symbol tables
  • 18. Inline caches Per-caller memoization, in code Fundamental optimization for property access Not as needed in Scheme because not much polymorphism Can allow efficient generic arithmetic Can make CLOS-style generics more efficient Clojure-like sequence protocols Function application?
  • 19. Dealing with the devil Runtime codegen in JS has a price: C++ Most Scheme implementations are self-hosted, with AOT compiler already Challenge: add adaptive optimization to existing Scheme implementation Requires good AOT compiler!
  • 20. JS can change the way we code Scheme’s static implementations encourage static programming define-integrable (declare (type fixnum x)) (declare (safety 0) (speed 3)) (declare (usual-integrations)) include instead of load Adaptive optimization can bring back dynamicity
  • 21. Summary In Smart vs Lazy, Schemers always chose Smart A bit of laziness won’t hurt Adaptive optimization in Scheme!
  • 22. questions? ❧ Work: http://www.igalia.com/compilers ❧ Words: http://wingolog.org/ ❧ Slides: http://wingolog.org/pub/qc-2012js-slides.pdf ❧ Notes: http://wingolog.org/pub/qc-2012js-notes.pdf