SlideShare una empresa de Scribd logo
1 de 47
Descargar para leer sin conexión
Bootstrap of Node.js Core
Joyee Cheung
Slides: https://github.com/nodejs/summit/issues/147
OpenJS collaboration summit, May 2019
A Node.js Process
Main Instance (JS thread)
Worker (if any)
(JS thread)
Task Scheduler
V8 Platform
thread pool
Inspector I/O
libuv
thread pool
Environment
Main V8
Context
VM V8
Context
V8 Isolate
Event
loop
Bootstrap (2019.05)
node::Start()
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,OpenSSL, ICU, signal handler…
node::Start()
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,OpenSSL, ICU, signal handler…
node::Start()
NodeMainInstance() / Worker()
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,OpenSSL, ICU, signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
JS heap, JS exceptions,
Microtask queue...
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,OpenSSL, ICU, signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
JS heap, JS exceptions,
Microtask queue...
global proxy, JS builtins
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,OpenSSL, ICU, signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Primordials
u JavaScript builtins like Object, Object.prototype are cloned onto
an object and frozen for internal use
u Users can delete Function.prototype.call
u WIP to transition all internal usage of these
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
libuv handles
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
libuv handles
inspector agent
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
bootstrap/*.js
global, process, task
queues, ESM/CJS
loaders ...
libuv handles
inspector agent
lib/internal/bootstrap/loaders.js
u Internal module loaders
u C++ binding loaders
u process.binding()
u process._linkedBinding()
u internalBinding()
u require() for loading other internal JavaScript modules
Built-in Modules (Native Modules)
lib/*.js
tools/js2c.py
NativeModuleLoader::LoadJavaScriptSource()
“use strict”;
...
static const uint16_t timers_raw[] = {
39,117,115,101...
};
JavaScript code
static data array
containing the source
Built-in Modules (Native Modules)
lib/*.js
tools/mkcodecache
NativeModuleEnv::InitializeCodeCache()
“use strict”;
...
static const uint8_t assert[] = {
165,3,222,192,132, ...
};
JavaScript code
static data array
containing the code cache
Built-in Modules (Native Modules)
Compiled with a special wrapper
that include access to more internals
function (exports, require, module, process,
internalBinding, primordials) {
require(‘internal/fs/utils’);
module.exports = {…};
}
lib/internal/bootstrap/node.js
u Set up most stuff on process and global
u C++ passes isMainThread, ownsProcessState into the script
u false for workers, true for the main thread
lib/internal/bootstrap/node.js
u Set up most stuff on process and global
u C++ passes isMainThread, ownsProcessState into the script
u false for workers, true for the main thread
u Set up JavaScript callbacks that will be added as v8::Persistent to the
Environment
u Async hook callbacks
u Timers & process.nextTick() schedulers
u Must not run async operations (not snapshottable)
u Must not depend on any CLI arguments or environment variables
lib/internal/bootstrap/pre_execution.js
u Not actively run. Required by main scripts (explained later)
u Bootstrap things that depend on CLI arguments and environment
variables
u Not included in the snapshot
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
bootstrap/*.js
main/?.js e.g.
run_main_module.js
global, process, task
queues, ESM/CJS
loaders ...
libuv handles
inspector agent
Main scripts
u lib/internal/main/*.js
u Main thread
uStartMainThreadExecution()
uSelect a script based on CLI arguments, etc.
u Worker threads
uworker_thread.js
u Runs lib/internal/bootstrap/pre_execution.js
first to bootstrap the parts that depend on run time states
Main scripts
u check_syntax.js: node –c test.js
u eval_stdin.js: cat test.js | node –e
u eval_string.js: node –e ‘1’
u inspect.js: node inspect ...
u print_bash_completion.js: node --completion-bash
u print_help.js: node --help
u prof_process.js: node --prof-process v8.log
Main scripts
u run_third_party_main.js
u Run lib/_third_party_main.js embedders
u environment.js
u For C++ test fixtures
Requested
u bundled cli tool entry point?
u better entry point for embedders?
Main scripts
u repl.js: node
u worker_thread.js: for workers
u run_main_module.js
u node index.js
u node --experimental-modules index.mjs
Main scripts
u repl.js: node
u run_main_module.js
u node index.js
u node --experimental-modules index.mjs
u worker_thread.js: for workers
lib/internal/bootstrap/pre_execution.js
u Bootstrap that depend on run time states
ue.g. CLI arguments, environment variables
uIncluding CJS & ESM loader initilization
if (!getOptionValue('--no-warnings') &&
process.env.NODE_NO_WARNINGS !== '1') {
process.on('warning', onWarning);
}
User land CommonJS Modules
function (exports, require, module, __filename, __dirname) {
require(‘fs’);
}
u Loader implemented in lib/internal/modules/cjs/
Wrap user code with objects initialized by Node.js
User land ECMAScript Modules
u Loader implementation in lib/internal/modules/esm/
u Does not mess with the context except things added to the
global proxy
uBuffer, process, etc.
User land ECMAScript Modules
u An internal WeakMap holding ModuleWrap -> Options
uOptions includes dynamic import() callback and
import.meta data
uPer-isolate
uHostImportModuleDynamicallyCallback
uHostInitializeImportMetaObjectCallback
Bootstrap (2019.05)
InitializeOncePerProcess()
Parse the CLI arguments, Initialize the V8
Platform,signal handler…
node::Start()
NodeMainInstance() / Worker()
v8::Isolate
v8::Context
node::Environment
do {
uv_run(...)
} while (...)
Event Loop
JS heap, JS exceptions,
Microtask queue...
per_context/*.js Node.js primordials
global proxy, JS builtins
Stuff that does not
have a better place to
go
bootstrap/*.js
main/?.js e.g.
run_main_module.js
global, process, task
queues, ESM/CJS
loaders ...
libuv handles
inspector agent
Snapshot Integration
out/Release/node --cpu-prof-interval=100 --cpu-prof -e "{}"
Snapshot Integration
out/Release/node --cpu-prof-interval=100 --cpu-prof -e "{}"
Can be snapshotted Depend on run time states
Snapshot Integration
d8 with default snapshot
node master without snapshot
Snapshot Integration v8::Isolate
v8::Context
node::Environment
per_context/*.js
bootstrap/*.js
main/?.js
loop & inspector
Original
SetIsolateUpForNode()
Snapshot Integration v8::Isolate
Context::FromSnapshot()
node::Environment
bootstrap/*.js
main/?.js
loop & inspector
SetIsolateUpForNode()
Snapshotted (2019.05)
Re-install callbacks
Snapshot Integration
Environment:: FromSnapshot()
Goal
Deserialize from snapshot instead of
executing per_context/*.js &
bootstrap/*.js
v8::Isolate
Context::FromSnapshot()
SetIsolateUpForNode()
Re-install callbacks
main/?.js
loop & inspector
Snapshot Integration
Environment:: FromSnapshot()
The bootstrap process must be
independent of run time states before
the snapshot is captured.
v8::Isolate
Context::FromSnapshot()
SetIsolateUpForNode()
Re-install callbacks
main/?.js
loop & inspector
Refactoring
Snapshot Integration
Used to be spaghetti mixed together
Snapshot Integration
Environment:: FromSnapshot()
v8::Isolate
Context::FromSnapshot()
SetIsolateUpForNode()
Re-install callbacks
main/?.js
loop & inspector
Refactoring
if (!getOptionValue('--no-warnings') &&
process.env.NODE_NO_WARNINGS !== '1') {
process.on('warning', onWarning);
}
lib/internal/bootstrap/pre_execution.js
Snapshot Integration
Environment:: FromSnapshot()
v8::Isolate
Context::FromSnapshot()
SetIsolateUpForNode()
Re-install callbacks
main/?.js
loop & inspector
Refactoring
Reorganize so that we can reinstall C++
states
Current state
u v12.3.1 v.s. v10.16.0
u ~60% faster child process startup
u ~120% faster worker startup
u Some refactoring has also been backported to v10 so the
actual speed up is higher
Current state
u v12.3.1 v.s. v10.16.0
u ~60% faster child process startup
u ~120% faster worker startup
u Some refactoring has also been backported to v10 so the
actual speed up is higher
u Mostly from lazy-loading and embedded code cache
u Further speedup anticipated from snapshot integration
u 4x in https://github.com/nodejs/node/issues/17058
Challenges
u Lack of reviews
u https://github.com/nodejs/node/pull/27539 27 days without
reviews
u Incrementally refactoring the spaghetti code + 7-day wait = slow
Challenges
u Lack of reviews
u https://github.com/nodejs/node/pull/27539 27 days without
reviews
u Incrementally refactoring the spaghetti code + 7-day wait = slow
u Fixed hash seed
u Rehashing maps & sets
u https://bugs.chromium.org/p/v8/issues/detail?id=9187
u Snapshot is currently still disabled on master behind a build time
flag
Future plans
u Finish integration before v12 LTS
u Explore user-land snapshot builder & loader
Thank you

Más contenido relacionado

La actualidad más candente

OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...Christopher Frohoff
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)Chris Cowan
 
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19Timur Shemsedinov
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterSimen Li
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMashleypuls
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js ModuleFred Chien
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization VulnerabilitiesLuca Carettoni
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfacesjuanvazquezslides
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensNETWAYS
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.jsorkaplan
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.jsguileen
 

La actualidad más candente (19)

OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
OWASP SD: Deserialize My Shorts: Or How I Learned To Start Worrying and Hate ...
 
NodeJS: an Introduction
NodeJS: an IntroductionNodeJS: an Introduction
NodeJS: an Introduction
 
Node.js 0.8 features
Node.js 0.8 featuresNode.js 0.8 features
Node.js 0.8 features
 
What is nodejs
What is nodejsWhat is nodejs
What is nodejs
 
Intro to Node.js (v1)
Intro to Node.js (v1)Intro to Node.js (v1)
Intro to Node.js (v1)
 
Introduction Node.js
Introduction Node.jsIntroduction Node.js
Introduction Node.js
 
Nodejs in Production
Nodejs in ProductionNodejs in Production
Nodejs in Production
 
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
Shared memory and multithreading in Node.js - Timur Shemsedinov - JSFest'19
 
Node.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitterNode.js Event Loop & EventEmitter
Node.js Event Loop & EventEmitter
 
Bytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASMBytecode manipulation with Javassist and ASM
Bytecode manipulation with Javassist and ASM
 
Fixing the Java Serialization Mess
Fixing the Java Serialization Mess Fixing the Java Serialization Mess
Fixing the Java Serialization Mess
 
How to Write Node.js Module
How to Write Node.js ModuleHow to Write Node.js Module
How to Write Node.js Module
 
Defending against Java Deserialization Vulnerabilities
 Defending against Java Deserialization Vulnerabilities Defending against Java Deserialization Vulnerabilities
Defending against Java Deserialization Vulnerabilities
 
Abusing Java Remote Interfaces
Abusing Java Remote InterfacesAbusing Java Remote Interfaces
Abusing Java Remote Interfaces
 
NodeJS
NodeJSNodeJS
NodeJS
 
Zabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet MensZabbix LLD from a C Module by Jan-Piet Mens
Zabbix LLD from a C Module by Jan-Piet Mens
 
Intro to Sail.js
Intro to Sail.jsIntro to Sail.js
Intro to Sail.js
 
introduction to node.js
introduction to node.jsintroduction to node.js
introduction to node.js
 
Why Node.js
Why Node.jsWhy Node.js
Why Node.js
 

Similar a Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.jsVikash Singh
 
Startup Snapshot in Node.js
Startup Snapshot in Node.jsStartup Snapshot in Node.js
Startup Snapshot in Node.jsIgalia
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDDSudar Muthu
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsDror Bereznitsky
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backendDavid Padbury
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.jsChris Cowan
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTudor Barbu
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS ExpressDavid Boyer
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiJackson Tian
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkAarti Parikh
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!🎤 Hanno Embregts 🎸
 

Similar a Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019) (20)

Introduction to Node.js
Introduction to Node.jsIntroduction to Node.js
Introduction to Node.js
 
node.js.pptx
node.js.pptxnode.js.pptx
node.js.pptx
 
5.node js
5.node js5.node js
5.node js
 
Startup Snapshot in Node.js
Startup Snapshot in Node.jsStartup Snapshot in Node.js
Startup Snapshot in Node.js
 
Nodejs Intro Part One
Nodejs Intro Part OneNodejs Intro Part One
Nodejs Intro Part One
 
NodeJS for Beginner
NodeJS for BeginnerNodeJS for Beginner
NodeJS for Beginner
 
Introduction to node.js GDD
Introduction to node.js GDDIntroduction to node.js GDD
Introduction to node.js GDD
 
Jdk Tools For Performance Diagnostics
Jdk Tools For Performance DiagnosticsJdk Tools For Performance Diagnostics
Jdk Tools For Performance Diagnostics
 
node.js: Javascript's in your backend
node.js: Javascript's in your backendnode.js: Javascript's in your backend
node.js: Javascript's in your backend
 
Intro To Node.js
Intro To Node.jsIntro To Node.js
Intro To Node.js
 
Testing frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabsTesting frontends with nightwatch & saucelabs
Testing frontends with nightwatch & saucelabs
 
All aboard the NodeJS Express
All aboard the NodeJS ExpressAll aboard the NodeJS Express
All aboard the NodeJS Express
 
Node
NodeNode
Node
 
Book
BookBook
Book
 
Why Nodejs Guilin Shanghai
Why Nodejs Guilin ShanghaiWhy Nodejs Guilin Shanghai
Why Nodejs Guilin Shanghai
 
Node.js quick intro
Node.js quick introNode.js quick intro
Node.js quick intro
 
Android ndk
Android ndkAndroid ndk
Android ndk
 
Original slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talkOriginal slides from Ryan Dahl's NodeJs intro talk
Original slides from Ryan Dahl's NodeJs intro talk
 
Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!Building a Spring Boot Application - Ask the Audience!
Building a Spring Boot Application - Ask the Audience!
 
Node.js 1, 2, 3
Node.js 1, 2, 3Node.js 1, 2, 3
Node.js 1, 2, 3
 

Más de Igalia

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?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 WPEIgalia
 
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...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 DevicesIgalia
 
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 MaintenanceIgalia
 
Optimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfOptimizing Scheduler for Linux Gaming.pdf
Optimizing Scheduler for Linux Gaming.pdfIgalia
 
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 JITIgalia
 
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!Igalia
 
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 GStreamerIgalia
 
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 MesaIgalia
 
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 IgaliaIgalia
 
2023 in Chimera Linux
2023 in Chimera                    Linux2023 in Chimera                    Linux
2023 in Chimera LinuxIgalia
 
Building a Linux distro with LLVM
Building a Linux distro        with LLVMBuilding a Linux distro        with LLVM
Building a Linux distro with LLVMIgalia
 
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 GPUsIgalia
 
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 devicesIgalia
 
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 ChromeOSIgalia
 
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 webIgalia
 
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 shadersIgalia
 
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...Igalia
 
Status of Vulkan on Raspberry
Status of Vulkan on RaspberryStatus of Vulkan on Raspberry
Status of Vulkan on RaspberryIgalia
 

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

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CVKhem
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreternaman860154
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024Results
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
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...Miguel Araújo
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfsudhanshuwaghmare1
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
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...Drew Madelung
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Servicegiselly40
 
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 RobisonAnna Loughnan Colquhoun
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?Antenna Manufacturer Coco
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
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.pdfUK Journal
 

Último (20)

Real Time Object Detection Using Open CV
Real Time Object Detection Using Open CVReal Time Object Detection Using Open CV
Real Time Object Detection Using Open CV
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
Presentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreterPresentation on how to chat with PDF using ChatGPT code interpreter
Presentation on how to chat with PDF using ChatGPT code interpreter
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 
A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024A Call to Action for Generative AI in 2024
A Call to Action for Generative AI in 2024
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
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...
 
Boost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdfBoost Fertility New Invention Ups Success Rates.pdf
Boost Fertility New Invention Ups Success Rates.pdf
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
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...
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
CNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of ServiceCNv6 Instructor Chapter 6 Quality of Service
CNv6 Instructor Chapter 6 Quality of Service
 
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
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?What Are The Drone Anti-jamming Systems Technology?
What Are The Drone Anti-jamming Systems Technology?
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
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
 

Bootstrap of Node.js Core (OpenJS Collaborator Summit Berlin 2019)

  • 1. Bootstrap of Node.js Core Joyee Cheung Slides: https://github.com/nodejs/summit/issues/147 OpenJS collaboration summit, May 2019
  • 2. A Node.js Process Main Instance (JS thread) Worker (if any) (JS thread) Task Scheduler V8 Platform thread pool Inspector I/O libuv thread pool Environment Main V8 Context VM V8 Context V8 Isolate Event loop
  • 4. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,OpenSSL, ICU, signal handler… node::Start()
  • 5. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,OpenSSL, ICU, signal handler… node::Start() NodeMainInstance() / Worker()
  • 6. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,OpenSSL, ICU, signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate JS heap, JS exceptions, Microtask queue...
  • 7. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,OpenSSL, ICU, signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context JS heap, JS exceptions, Microtask queue... global proxy, JS builtins
  • 8. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,OpenSSL, ICU, signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins
  • 9. Primordials u JavaScript builtins like Object, Object.prototype are cloned onto an object and frozen for internal use u Users can delete Function.prototype.call u WIP to transition all internal usage of these
  • 10. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go
  • 11. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go libuv handles
  • 12. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go libuv handles inspector agent
  • 13. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go bootstrap/*.js global, process, task queues, ESM/CJS loaders ... libuv handles inspector agent
  • 14. lib/internal/bootstrap/loaders.js u Internal module loaders u C++ binding loaders u process.binding() u process._linkedBinding() u internalBinding() u require() for loading other internal JavaScript modules
  • 15. Built-in Modules (Native Modules) lib/*.js tools/js2c.py NativeModuleLoader::LoadJavaScriptSource() “use strict”; ... static const uint16_t timers_raw[] = { 39,117,115,101... }; JavaScript code static data array containing the source
  • 16. Built-in Modules (Native Modules) lib/*.js tools/mkcodecache NativeModuleEnv::InitializeCodeCache() “use strict”; ... static const uint8_t assert[] = { 165,3,222,192,132, ... }; JavaScript code static data array containing the code cache
  • 17. Built-in Modules (Native Modules) Compiled with a special wrapper that include access to more internals function (exports, require, module, process, internalBinding, primordials) { require(‘internal/fs/utils’); module.exports = {…}; }
  • 18. lib/internal/bootstrap/node.js u Set up most stuff on process and global u C++ passes isMainThread, ownsProcessState into the script u false for workers, true for the main thread
  • 19. lib/internal/bootstrap/node.js u Set up most stuff on process and global u C++ passes isMainThread, ownsProcessState into the script u false for workers, true for the main thread u Set up JavaScript callbacks that will be added as v8::Persistent to the Environment u Async hook callbacks u Timers & process.nextTick() schedulers u Must not run async operations (not snapshottable) u Must not depend on any CLI arguments or environment variables
  • 20. lib/internal/bootstrap/pre_execution.js u Not actively run. Required by main scripts (explained later) u Bootstrap things that depend on CLI arguments and environment variables u Not included in the snapshot
  • 21. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go bootstrap/*.js main/?.js e.g. run_main_module.js global, process, task queues, ESM/CJS loaders ... libuv handles inspector agent
  • 22. Main scripts u lib/internal/main/*.js u Main thread uStartMainThreadExecution() uSelect a script based on CLI arguments, etc. u Worker threads uworker_thread.js u Runs lib/internal/bootstrap/pre_execution.js first to bootstrap the parts that depend on run time states
  • 23. Main scripts u check_syntax.js: node –c test.js u eval_stdin.js: cat test.js | node –e u eval_string.js: node –e ‘1’ u inspect.js: node inspect ... u print_bash_completion.js: node --completion-bash u print_help.js: node --help u prof_process.js: node --prof-process v8.log
  • 24. Main scripts u run_third_party_main.js u Run lib/_third_party_main.js embedders u environment.js u For C++ test fixtures Requested u bundled cli tool entry point? u better entry point for embedders?
  • 25. Main scripts u repl.js: node u worker_thread.js: for workers u run_main_module.js u node index.js u node --experimental-modules index.mjs
  • 26. Main scripts u repl.js: node u run_main_module.js u node index.js u node --experimental-modules index.mjs u worker_thread.js: for workers
  • 27. lib/internal/bootstrap/pre_execution.js u Bootstrap that depend on run time states ue.g. CLI arguments, environment variables uIncluding CJS & ESM loader initilization if (!getOptionValue('--no-warnings') && process.env.NODE_NO_WARNINGS !== '1') { process.on('warning', onWarning); }
  • 28. User land CommonJS Modules function (exports, require, module, __filename, __dirname) { require(‘fs’); } u Loader implemented in lib/internal/modules/cjs/ Wrap user code with objects initialized by Node.js
  • 29. User land ECMAScript Modules u Loader implementation in lib/internal/modules/esm/ u Does not mess with the context except things added to the global proxy uBuffer, process, etc.
  • 30. User land ECMAScript Modules u An internal WeakMap holding ModuleWrap -> Options uOptions includes dynamic import() callback and import.meta data uPer-isolate uHostImportModuleDynamicallyCallback uHostInitializeImportMetaObjectCallback
  • 31. Bootstrap (2019.05) InitializeOncePerProcess() Parse the CLI arguments, Initialize the V8 Platform,signal handler… node::Start() NodeMainInstance() / Worker() v8::Isolate v8::Context node::Environment do { uv_run(...) } while (...) Event Loop JS heap, JS exceptions, Microtask queue... per_context/*.js Node.js primordials global proxy, JS builtins Stuff that does not have a better place to go bootstrap/*.js main/?.js e.g. run_main_module.js global, process, task queues, ESM/CJS loaders ... libuv handles inspector agent
  • 33. Snapshot Integration out/Release/node --cpu-prof-interval=100 --cpu-prof -e "{}" Can be snapshotted Depend on run time states
  • 34. Snapshot Integration d8 with default snapshot node master without snapshot
  • 36. Snapshot Integration v8::Isolate Context::FromSnapshot() node::Environment bootstrap/*.js main/?.js loop & inspector SetIsolateUpForNode() Snapshotted (2019.05) Re-install callbacks
  • 37. Snapshot Integration Environment:: FromSnapshot() Goal Deserialize from snapshot instead of executing per_context/*.js & bootstrap/*.js v8::Isolate Context::FromSnapshot() SetIsolateUpForNode() Re-install callbacks main/?.js loop & inspector
  • 38. Snapshot Integration Environment:: FromSnapshot() The bootstrap process must be independent of run time states before the snapshot is captured. v8::Isolate Context::FromSnapshot() SetIsolateUpForNode() Re-install callbacks main/?.js loop & inspector Refactoring
  • 39. Snapshot Integration Used to be spaghetti mixed together
  • 40. Snapshot Integration Environment:: FromSnapshot() v8::Isolate Context::FromSnapshot() SetIsolateUpForNode() Re-install callbacks main/?.js loop & inspector Refactoring if (!getOptionValue('--no-warnings') && process.env.NODE_NO_WARNINGS !== '1') { process.on('warning', onWarning); } lib/internal/bootstrap/pre_execution.js
  • 41. Snapshot Integration Environment:: FromSnapshot() v8::Isolate Context::FromSnapshot() SetIsolateUpForNode() Re-install callbacks main/?.js loop & inspector Refactoring Reorganize so that we can reinstall C++ states
  • 42. Current state u v12.3.1 v.s. v10.16.0 u ~60% faster child process startup u ~120% faster worker startup u Some refactoring has also been backported to v10 so the actual speed up is higher
  • 43. Current state u v12.3.1 v.s. v10.16.0 u ~60% faster child process startup u ~120% faster worker startup u Some refactoring has also been backported to v10 so the actual speed up is higher u Mostly from lazy-loading and embedded code cache u Further speedup anticipated from snapshot integration u 4x in https://github.com/nodejs/node/issues/17058
  • 44. Challenges u Lack of reviews u https://github.com/nodejs/node/pull/27539 27 days without reviews u Incrementally refactoring the spaghetti code + 7-day wait = slow
  • 45. Challenges u Lack of reviews u https://github.com/nodejs/node/pull/27539 27 days without reviews u Incrementally refactoring the spaghetti code + 7-day wait = slow u Fixed hash seed u Rehashing maps & sets u https://bugs.chromium.org/p/v8/issues/detail?id=9187 u Snapshot is currently still disabled on master behind a build time flag
  • 46. Future plans u Finish integration before v12 LTS u Explore user-land snapshot builder & loader