SlideShare una empresa de Scribd logo
1 de 27
Descargar para leer sin conexión
Stranger in These
Parts
A Hired Gun in the JS Corral
Andy Wingo
JSConf 2012
Howdy!
Compiler nerd
Working for Igalia
❧ Free Software Consulting
❧ 3rd largest corporate contributor to WebKit,
after Google and Apple
❧ Based in Spain
❧ Worker-owned cooperative
Not From Around Here
Schemer (implementor, user)
Learned a lot from JS implementations
Implementation, performance perspective
Focus on JavaScriptCore (JSC)
Songs Of My People
Peter Norvig: PAIP (1992)
“There are 4 general techniques for speeding up
an algorithm
❧ Caching
❧ Compiling
❧ Delaying computation [laziness]
❧ Indexing [better big-O data structures]”
Example: Inline Caches
You see x+y. How to implement? V8/Dart
approach:
❧ Delay: wait until it is run
❧ Compile: a version of + specialized to the
types at that call site
❧ Cache: that code in a stub
Same applies to field access: x.y
An IC is also data
Lazy Compilation in JSC
Tiered compilation
0. Interpret cold code: the LLInt
1. Compile warm code: the Baseline JIT
2. Optimize hot code: the DFG JIT
Laziness; Impatience; Hubris
Tier 0: The LLInt
“Low-level interpreter”
Interprets byte-compiled code
New: 6 weeks old; by Filip Pizlo
Deep dive for context
Bytecode
$ jsc -d
> function foo(x,y) { return x+y; }
Bytecode
$ jsc -d
> function foo(x,y) { return x+y; }
[
0] enter
[
1] mov
r0, Undefined(@k0)
[
4] end
r0
undefined
Where's the code?
Lazy Bytecompilation
Parse and bytecompile on first call.
> foo(2,3)
[
0] enter
[
1] add
[
6] ret
5

r0, r-8, r-9
r0
Classic Interpreter
2008's “SquirrelFish”
Interpreter.cpp
#define NEXT_INSTRUCTION() goto *vPC->u.opcode
DEFINE_OPCODE(op_add) {
/* add dst(r) src1(r) src2(r)
Adds register src1 and register src2, and puts the result
in register dst. (JS add may be string concatenation or
numeric add, depending on the types of the operands.)

}

*/
int dst = vPC[1].u.operand;
JSValue src1 = callFrame->r(vPC[2].u.operand).jsValue();
JSValue src2 = callFrame->r(vPC[3].u.operand).jsValue();
if (src1.isInt32() && src2.isInt32() && !((src1.asInt32() | src2.asIn
callFrame->uncheckedR(dst) = jsNumber(src1.asInt32() + src2.asInt
else {
JSValue result = jsAdd(callFrame, src1, src2);
CHECK_FOR_EXCEPTION();
callFrame->uncheckedR(dst) = result;
}
vPC += OPCODE_LENGTH(op_add);
NEXT_INSTRUCTION();
.
The LLInt
Instead of C++, domain-specific language
Compiled by custom Ruby macroassembler
LowLevelInterpreter64.asm
macro dispatch(advance)
addp advance, PC
jmp [PB, PC, 8]
end
_llint_op_init_lazy_reg:
traceExecution()
loadis 8[PB, PC, 8], t0
storep ValueEmpty, [cfr, t0, 8]
dispatch(2)
macro binaryOp(integerOperation, doubleOperation, slowPath)
# ...
end
_llint_op_add:
traceExecution()
binaryOp(
macro (left, right, slow) baddio left, right, slow end,
macro (left, right) addd left, right end,
_llint_slow_path_add)
Why LLInt: Control
Control of stack layout
❧ OSR possible
❧ GC more precise
❧ Same calling convention as JIT
Control of code
❧ Better register allocation
❧ Tighter code / better locality
❧ Better control over inlining
Incidentals
It's much faster
Value profiles
Sandbox-friendly (iOS W/X restrictions)
Tier 1: Baseline JIT
Essentially: an LLInt without dispatch, with ICs,
and some small optimizations.
2009's “Squirrelfish Extreme”
JITArithmetic.cpp

void JIT::emit_op_add(Instruction* currentInstruction) {
unsigned result = currentInstruction[1].u.operand;
unsigned op1 = currentInstruction[2].u.operand;
unsigned op2 = currentInstruction[3].u.operand;
OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.op
if (!types.first().mightBeNumber() || !types.second().mightBeNumber()
// slow case: stub call
}
if (isOperandConstantImmediateInt(op1)) {
emitGetVirtualRegister(op2, regT0);
emitJumpSlowCaseIfNotImmediateInteger(regT0);
addSlowCase(branchAdd32(Overflow, regT0, Imm32(getConstantOperand
emitFastArithIntToImmNoCheck(regT1, regT0);
} else if (isOperandConstantImmediateInt(op2)) {
// same as before
} else
// general case (includes int and double fast paths)
compileBinaryArithOp(op_add, result, op1, op2, types);
emitPutVirtualRegister(result);
}
Tier 2: The DFG JIT
“Data-flow-graph”
Speculative, type-specific, feedback-driven
Uses value profiles from baseline JIT, LLInt
Big wins: unboxing, native arithmetic & object
access, dynamic inlining, register allocation
Like Crankshaft, HotSpot
DFGSpeculativeJIT.cpp
// abbreviated
void SpeculativeJIT::compileAdd(Node& node) {
if (m_jit.graph().addShouldSpeculateInteger(node)) {
// special cases for constant integer addends
if (isNumberConstant(node.child1().index())) { /* ... */ }
if (isNumberConstant(node.child2().index())) { /* ... */ }

}

// load args from registers, assert they are integers, add, check
// for overflow if necessary, return integer.

if (Node::shouldSpeculateNumber(at(node.child1()), at(node.child2()))
// load args from registers, assert they are doubles, add, return
}
if (node.op() == ValueAdd) {
// string concatenation
}

}

// fail
terminateSpeculativeExecution(Uncountable, JSValueRegs(), NoNode);
Ports, Platforms, and Tiering
Mac: LLInt + Baseline JIT + DFG
GTK+: Baseline JIT + DFG
Win64: Classic Interpreter
The Fifth Element
❧ Caching
❧ Compiling
❧ Delaying computation
❧ Indexing
The Fifth Element
❧ Caching
❧ Compiling
❧ Delaying computation
❧ Indexing
❧ Concurrency
Parallel GC
Stop-the-world, mark-and-sweep
Parallelize mark phase: 4 cores on current MBP
hardware
Decreases pause time
Strange Loops
Norvig: The expert Lisp programmer eventually
develops a good “efficiency model”
But: the efficiency model changes over time!
JS developers in the loop: bug reports,
benchmark suites
~ fin ~
❧ wingo@igalia.com
❧ http://wingolog.org/

Más contenido relacionado

La actualidad más candente

ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
Amos Wenger
 

La actualidad más candente (20)

A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul PillaiA look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
A look into the sanitizer family (ASAN & UBSAN) by Akul Pillai
 
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
서버 개발자가 바라 본 Functional Reactive Programming with RxJava - SpringCamp2015
 
NS2 Object Construction
NS2 Object ConstructionNS2 Object Construction
NS2 Object Construction
 
Do while loop
Do while loopDo while loop
Do while loop
 
20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料20170127 tokyoserversideswiftmeetup資料
20170127 tokyoserversideswiftmeetup資料
 
Crange: Clang based tool to index and cross-reference C/C++ source code
Crange: Clang based tool to index and cross-reference C/C++ source code Crange: Clang based tool to index and cross-reference C/C++ source code
Crange: Clang based tool to index and cross-reference C/C++ source code
 
[C++ korea] effective modern c++ study item 4 - 6 신촌
[C++ korea] effective modern c++ study   item 4 - 6 신촌[C++ korea] effective modern c++ study   item 4 - 6 신촌
[C++ korea] effective modern c++ study item 4 - 6 신촌
 
NS2 Classifiers
NS2 ClassifiersNS2 Classifiers
NS2 Classifiers
 
A Case for Relativistic Programming
A Case for Relativistic ProgrammingA Case for Relativistic Programming
A Case for Relativistic Programming
 
Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...Asynchronous single page applications without a line of HTML or Javascript, o...
Asynchronous single page applications without a line of HTML or Javascript, o...
 
Software transactional memory. pure functional approach
Software transactional memory. pure functional approachSoftware transactional memory. pure functional approach
Software transactional memory. pure functional approach
 
Start Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New RopeStart Wrap Episode 11: A New Rope
Start Wrap Episode 11: A New Rope
 
Q4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-VectorizerQ4.11: Using GCC Auto-Vectorizer
Q4.11: Using GCC Auto-Vectorizer
 
ooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wengerooc - OSDC 2010 - Amos Wenger
ooc - OSDC 2010 - Amos Wenger
 
Zarzadzanie pamiecia w .NET - WDI
Zarzadzanie pamiecia w .NET - WDIZarzadzanie pamiecia w .NET - WDI
Zarzadzanie pamiecia w .NET - WDI
 
Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2Basic Packet Forwarding in NS2
Basic Packet Forwarding in NS2
 
NS2 Shadow Object Construction
NS2 Shadow Object ConstructionNS2 Shadow Object Construction
NS2 Shadow Object Construction
 
Introduction to gdb
Introduction to gdbIntroduction to gdb
Introduction to gdb
 
Java performance jit
Java performance jitJava performance jit
Java performance jit
 
Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)Algorithm and Programming (Looping Structure)
Algorithm and Programming (Looping Structure)
 

Similar a Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)

20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
imec.archive
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Juan Fumero
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon Berlin
 

Similar a Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012) (20)

Open source report writing tools for IBM i Vienna 2012
Open source report writing tools for IBM i  Vienna 2012Open source report writing tools for IBM i  Vienna 2012
Open source report writing tools for IBM i Vienna 2012
 
Beyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic AnalysisBeyond Breakpoints: A Tour of Dynamic Analysis
Beyond Breakpoints: A Tour of Dynamic Analysis
 
Android RenderScript
Android RenderScriptAndroid RenderScript
Android RenderScript
 
2.1 ### uVision Project, (C) Keil Software .docx
2.1   ### uVision Project, (C) Keil Software    .docx2.1   ### uVision Project, (C) Keil Software    .docx
2.1 ### uVision Project, (C) Keil Software .docx
 
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the CompilerPragmatic Optimization in Modern Programming - Demystifying the Compiler
Pragmatic Optimization in Modern Programming - Demystifying the Compiler
 
LAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
LAS16-501: Introduction to LLVM - Projects, Components, Integration, InternalsLAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
LAS16-501: Introduction to LLVM - Projects, Components, Integration, Internals
 
RxJava on Android
RxJava on AndroidRxJava on Android
RxJava on Android
 
Boosting Developer Productivity with Clang
Boosting Developer Productivity with ClangBoosting Developer Productivity with Clang
Boosting Developer Productivity with Clang
 
Taipei.py 2018 - Control device via ioctl from Python
Taipei.py 2018 - Control device via ioctl from Python Taipei.py 2018 - Control device via ioctl from Python
Taipei.py 2018 - Control device via ioctl from Python
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Static analysis of C++ source code
Static analysis of C++ source codeStatic analysis of C++ source code
Static analysis of C++ source code
 
Xdp and ebpf_maps
Xdp and ebpf_mapsXdp and ebpf_maps
Xdp and ebpf_maps
 
Multiplatform JIT Code Generator for NetBSD by Alexander Nasonov
Multiplatform JIT Code Generator for NetBSD by Alexander NasonovMultiplatform JIT Code Generator for NetBSD by Alexander Nasonov
Multiplatform JIT Code Generator for NetBSD by Alexander Nasonov
 
Gpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cudaGpu workshop cluster universe: scripting cuda
Gpu workshop cluster universe: scripting cuda
 
Linux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloudLinux kernel tracing superpowers in the cloud
Linux kernel tracing superpowers in the cloud
 
Deuce STM - CMP'09
Deuce STM - CMP'09Deuce STM - CMP'09
Deuce STM - CMP'09
 
20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris20081114 Friday Food iLabt Bart Joris
20081114 Friday Food iLabt Bart Joris
 
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in JavaRuntime Code Generation and Data Management for Heterogeneous Computing in Java
Runtime Code Generation and Data Management for Heterogeneous Computing in Java
 
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDKEric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
Eric Lafortune - ProGuard: Optimizer and obfuscator in the Android SDK
 
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
Droidcon2013 pro guard, optimizer and obfuscator in the android sdk_eric lafo...
 

Más de 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
 

Más de 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
 

Último

Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 
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
 

Último (20)

Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
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
 
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)
 
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
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
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...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
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...
 
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
 
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
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
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
 
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
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
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...
 

Stranger in These Parts. A Hired Gun in the JS Corral (JSConf US 2012)

  • 1. Stranger in These Parts A Hired Gun in the JS Corral Andy Wingo JSConf 2012
  • 2. Howdy! Compiler nerd Working for Igalia ❧ Free Software Consulting ❧ 3rd largest corporate contributor to WebKit, after Google and Apple ❧ Based in Spain ❧ Worker-owned cooperative
  • 3. Not From Around Here Schemer (implementor, user) Learned a lot from JS implementations Implementation, performance perspective Focus on JavaScriptCore (JSC)
  • 4. Songs Of My People Peter Norvig: PAIP (1992) “There are 4 general techniques for speeding up an algorithm ❧ Caching ❧ Compiling ❧ Delaying computation [laziness] ❧ Indexing [better big-O data structures]”
  • 5. Example: Inline Caches You see x+y. How to implement? V8/Dart approach: ❧ Delay: wait until it is run ❧ Compile: a version of + specialized to the types at that call site ❧ Cache: that code in a stub Same applies to field access: x.y An IC is also data
  • 6. Lazy Compilation in JSC Tiered compilation 0. Interpret cold code: the LLInt 1. Compile warm code: the Baseline JIT 2. Optimize hot code: the DFG JIT Laziness; Impatience; Hubris
  • 7. Tier 0: The LLInt “Low-level interpreter” Interprets byte-compiled code New: 6 weeks old; by Filip Pizlo Deep dive for context
  • 8. Bytecode $ jsc -d > function foo(x,y) { return x+y; }
  • 9. Bytecode $ jsc -d > function foo(x,y) { return x+y; } [ 0] enter [ 1] mov r0, Undefined(@k0) [ 4] end r0 undefined Where's the code?
  • 10. Lazy Bytecompilation Parse and bytecompile on first call. > foo(2,3) [ 0] enter [ 1] add [ 6] ret 5 r0, r-8, r-9 r0
  • 12. Interpreter.cpp #define NEXT_INSTRUCTION() goto *vPC->u.opcode DEFINE_OPCODE(op_add) { /* add dst(r) src1(r) src2(r) Adds register src1 and register src2, and puts the result in register dst. (JS add may be string concatenation or numeric add, depending on the types of the operands.) } */ int dst = vPC[1].u.operand; JSValue src1 = callFrame->r(vPC[2].u.operand).jsValue(); JSValue src2 = callFrame->r(vPC[3].u.operand).jsValue(); if (src1.isInt32() && src2.isInt32() && !((src1.asInt32() | src2.asIn callFrame->uncheckedR(dst) = jsNumber(src1.asInt32() + src2.asInt else { JSValue result = jsAdd(callFrame, src1, src2); CHECK_FOR_EXCEPTION(); callFrame->uncheckedR(dst) = result; } vPC += OPCODE_LENGTH(op_add); NEXT_INSTRUCTION();
  • 13. .
  • 14. The LLInt Instead of C++, domain-specific language Compiled by custom Ruby macroassembler
  • 15. LowLevelInterpreter64.asm macro dispatch(advance) addp advance, PC jmp [PB, PC, 8] end _llint_op_init_lazy_reg: traceExecution() loadis 8[PB, PC, 8], t0 storep ValueEmpty, [cfr, t0, 8] dispatch(2) macro binaryOp(integerOperation, doubleOperation, slowPath) # ... end _llint_op_add: traceExecution() binaryOp( macro (left, right, slow) baddio left, right, slow end, macro (left, right) addd left, right end, _llint_slow_path_add)
  • 16. Why LLInt: Control Control of stack layout ❧ OSR possible ❧ GC more precise ❧ Same calling convention as JIT Control of code ❧ Better register allocation ❧ Tighter code / better locality ❧ Better control over inlining
  • 17. Incidentals It's much faster Value profiles Sandbox-friendly (iOS W/X restrictions)
  • 18. Tier 1: Baseline JIT Essentially: an LLInt without dispatch, with ICs, and some small optimizations. 2009's “Squirrelfish Extreme”
  • 19. JITArithmetic.cpp void JIT::emit_op_add(Instruction* currentInstruction) { unsigned result = currentInstruction[1].u.operand; unsigned op1 = currentInstruction[2].u.operand; unsigned op2 = currentInstruction[3].u.operand; OperandTypes types = OperandTypes::fromInt(currentInstruction[4].u.op if (!types.first().mightBeNumber() || !types.second().mightBeNumber() // slow case: stub call } if (isOperandConstantImmediateInt(op1)) { emitGetVirtualRegister(op2, regT0); emitJumpSlowCaseIfNotImmediateInteger(regT0); addSlowCase(branchAdd32(Overflow, regT0, Imm32(getConstantOperand emitFastArithIntToImmNoCheck(regT1, regT0); } else if (isOperandConstantImmediateInt(op2)) { // same as before } else // general case (includes int and double fast paths) compileBinaryArithOp(op_add, result, op1, op2, types); emitPutVirtualRegister(result); }
  • 20. Tier 2: The DFG JIT “Data-flow-graph” Speculative, type-specific, feedback-driven Uses value profiles from baseline JIT, LLInt Big wins: unboxing, native arithmetic & object access, dynamic inlining, register allocation Like Crankshaft, HotSpot
  • 21. DFGSpeculativeJIT.cpp // abbreviated void SpeculativeJIT::compileAdd(Node& node) { if (m_jit.graph().addShouldSpeculateInteger(node)) { // special cases for constant integer addends if (isNumberConstant(node.child1().index())) { /* ... */ } if (isNumberConstant(node.child2().index())) { /* ... */ } } // load args from registers, assert they are integers, add, check // for overflow if necessary, return integer. if (Node::shouldSpeculateNumber(at(node.child1()), at(node.child2())) // load args from registers, assert they are doubles, add, return } if (node.op() == ValueAdd) { // string concatenation } } // fail terminateSpeculativeExecution(Uncountable, JSValueRegs(), NoNode);
  • 22. Ports, Platforms, and Tiering Mac: LLInt + Baseline JIT + DFG GTK+: Baseline JIT + DFG Win64: Classic Interpreter
  • 23. The Fifth Element ❧ Caching ❧ Compiling ❧ Delaying computation ❧ Indexing
  • 24. The Fifth Element ❧ Caching ❧ Compiling ❧ Delaying computation ❧ Indexing ❧ Concurrency
  • 25. Parallel GC Stop-the-world, mark-and-sweep Parallelize mark phase: 4 cores on current MBP hardware Decreases pause time
  • 26. Strange Loops Norvig: The expert Lisp programmer eventually develops a good “efficiency model” But: the efficiency model changes over time! JS developers in the loop: bug reports, benchmark suites
  • 27. ~ fin ~ ❧ wingo@igalia.com ❧ http://wingolog.org/