Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Node 8 and Friends

Node 8 and Friends

What's new in Node.js?

Minqi Pan

June 28, 2017
Tweet

More Decks by Minqi Pan

Other Decks in Programming

Transcript

  1. Agenda • to be covered • new spotlights of Node

    8 and recent releases • new topics of the Node.js ecosystem • NOT to be covered • technical bug fixes or improvements on details
  2. a JavaScript engine developed by The Chromium Project for the

    Google Chrome web browser since 9 years ago
  3. v8: every 1½ months 6.0 2017 / 6 / 9

    5.9 2017 / 4 / 27 5.8 2017 / 3 / 20
  4. Chrome: every 1½ months 59 2017 / 6 / 5

    58 2017 / 4 / 19 57 2017 / 3 / 9
  5. Chrome: 
 1 release behind v8 59 2017 / 6

    / 5 ca. release date of v8 6.0 58 2017 / 4 / 19 ca. release date of v8 5.9 57 2017 / 3 / 9 ca. release date of v8 5.8
  6. Chrome DevTools Protocol • Node deprecated old debugger protocol in

    favor of
 Chrome DevTools Protocol via websocket (v8_inspector from Blink) • chrome://inspect
  7. Chrome Trace Event • Centralize tracing information generated by V8,

    Node core, and user-space code. • Traces are visualizable • chrome://tracing/
  8. (Possibly) Unified APM • APM monkey-patches Node.js to monitor performance

    • instrumentation via v8 trace events API made possible • possible to provide a unified instrumentation API based on v8 trace events
  9. Node.js: 2~4 releases behind v8 8.1.0 / v8 5.8 2017

    / 6 / 7 ca. release date of v8 6.0 8.0.0 / v8 5.8 2017 / 5 / 30 ca. release date of v8 6.0 7.10.0 / v8 5.5 2017 / 5 / 2 ca. release date of v8 5.9
  10. More help from Google • Silver member of Node.js Foundation

    • Google Cloud Platform supports Node.js on Compute Engine, Container Engine, App Engine and Cloud Functions • … w/ SDK and monitoring (Google Stackdriver)
  11. node 8 waits for v8 5.8 • --turbo --ignition •

    will be enabled by default in v8 5.9 • Crankshaft-script => TurboFan-Script
  12. node 8 waits for v8 5.8 • V8 team is

    preparing special versions of 5.8 that are ABI compatible to 6.0 (Node.js LTS) • Allow Node.js to upgrade to the new pipeline as a non-breaking change • simpler script execution pipeline; reduce jank; make the interchange between V8’s various components more efficient
  13. Ignition • Reducing memory usage w/ compact byte-code • Enables

    Android devices with small memory • Improves the startup speed via byte-code caching • refactoring v8
  14. Ignition • cf. Apple’s JavaScriptCore + SquirrelFish (Nitro)
 cf. Mozilla’s

    SpiderMonkey + IonMonkey
 cf. Microsoft’s ChakraCore + its JIT • cf. .java -> javac -> .class (bytecode)
 .class -> hot -> JIT -> machine code • cf. .rb -> RubyVM::InstructionSequence
  15. Design of Ignition • Concise • so that Bytecode size

    have a small memory footprint (machine code generated by V8’s full- codegen compiler is verbose) • so that we always compile it eagerly • so that initial startup is faster
  16. Chromium #593477 Open Chrome 51 (canary) (1) Load www.facebook.com multiple

    times in the browser (2) exit the browser, open about:tracing and record all enabled by default categories
  17. Chromium #593477 Result: (1) initial load, v8.CompileScript takes 165 ms

    (2) repeated loads, V8.ParseLazy takes 376 ms
  18. Chromium #593477 Why? - Entirely compile eagerly are too costly

    (Being included in the code cache increases both the footprint on the hard disk and takes longer to serialize and deserialize. let alone the memory…) - So only the toplevel code gets compiled - Functions contained is compiled until the function is actually called - Lazily compiling inner functions still requires a new parsing pass
  19. TurboFan • V8's new optimizing compiler • Architecture-independent macro-assembly instructions:

    handlers of Ignition’s bytecode • compiles Ignition instructions to the target architecture • performing instruction selection and machine register allocation
  20. TurboFan • replace Full Codegen and Crankshaft • Optimize what

    Crankshaft cannot optimize • support ES2015+ • w/ Escape analysis
  21. Async Hooks • Node 8’s API for setting up hooks

    to get structural tracing information about the life of handle objects • monitoring the operation of the Node.js event loop • tracking asynchronous requests and handles through their complete lifecycle
  22. Node.js Native API (NAPI) • NAN: insulate from v8 API

    Changes • Node 8’s NAPI: insulate from v8 itself • Stable on both API and ABI • Supports Node-ChakraCore, SpiderNode
  23. Node.js Native API (NAPI) • Use C instead of C++

    to avoid Name Mangling • All v8 JavaScript value become napi_value • deprecate v8 exceptions, all NAPI returns napi_status • redesigned scope, now uses napi_open_handle_scope
  24. nodec v1.0.0 • upgrade runtime to node 8 • add

    runtime support for native modules • allow executing files within the enclosed package • allow reusing itself as an Node.js interpreter • add auto-update feature
  25. Compiling to Bytecode? • FE has limited battery, memory, network

    resources. • FE usually won’t ship a lot of unused code • Node.js has big node_modules folder so cost of eagerly compiling all is still huge • But we have mmap; works good on a single file • IP (Intellectual Property) Protection
  26. “ vm.Script could be used to hide the source by

    shipping only bytecode” https://github.com/nodejs/node/issues/11842 “ AST, IR, bytecode and friends - standards and inovation” https://github.com/nodejs/CTC/issues/104
  27. nodec v2.0.0 plan • Eagerly compile everything into Bytecode, including

    node_modules • Put them inside a SquashFS (i.e. your.exe) • OS mmaps your.exe when executed • Enjoy low memory footprint and fast startup • No source code shipped