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?

8002c84eb4c18170632f8fb7efb09288?s=128

Minqi Pan

June 28, 2017
Tweet

Transcript

  1. Node 8 and Friends Minqi Pan

  2. None
  3. Invented by Ryan Dahl Inaugurated on JSConf EU 8 years

    ago
  4. 2009 2017 Google Trends

  5. 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
  6. None
  7. a JavaScript engine developed by The Chromium Project for the

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

    5.9 2017 / 4 / 27 5.8 2017 / 3 / 20
  9. v8: every 1½ months 6.1 ca. 2017 / 7 /

    21
  10. None
  11. a web browser developed by Google since 9 years ago

  12. Chrome: every 1½ months 59 2017 / 6 / 5

    58 2017 / 4 / 19 57 2017 / 3 / 9
  13. 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
  14. 58 5.8.283.38 59 5.9.211.35 60 6.0.286.15 61 6.1.120

  15. (Version of Chrome) / 10 = Version of v8

  16. Chrome DevTools Protocol • Node deprecated old debugger protocol in

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

    Node core, and user-space code. • Traces are visualizable • chrome://tracing/
  21. None
  22. (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
  23. None
  24. None
  25. None
  26. 8.1.1 Current 5.8 6.11.0 LTS 5.1 4.8.3 4.5

  27. 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
  28. 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)
  29. None
  30. Active integrations between v8 and Node.js • https://github.com/v8/node/ • https://github.com/nodejs/node-v8

    • Branch “canary-base” of • https://github.com/nodejs/node
  31. Node.js Jenkins CI a v8-updating robot https://github.com/nodejs-ci

  32. ES2017

  33. None
  34. None
  35. None
  36. None
  37. None
  38. None
  39. (async () => {})()

  40. None
  41. None
  42. None
  43. None
  44. None
  45. Chrome 61

  46. None
  47. http://node.green/

  48. None
  49. node 8 waits for v8 5.8 • --turbo --ignition •

    will be enabled by default in v8 5.9 • Crankshaft-script => TurboFan-Script
  50. 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
  51. None
  52. Ignition • Reducing memory usage w/ compact byte-code • Enables

    Android devices with small memory • Improves the startup speed via byte-code caching • refactoring v8
  53. 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
  54. 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
  55. 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
  56. Chromium #593477 Result: (1) initial load, v8.CompileScript takes 165 ms

    (2) repeated loads, V8.ParseLazy takes 376 ms
  57. 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
  58. Facebook uses a transpiler to combine individual modules into a

    single file. E.g. Chromium #593477
  59. Old Architecture

  60. Multiple Parsing Machine Code

  61. might never run again N-level-nested function is parsed N times

  62. New Architecture

  63. Memory Problem JIT-ed code

  64. Memory Optimized

  65. Mobile Top 10 Benchmark

  66. run-once or non-hot code now stored more compactly in bytecode

    form
  67. Startup Speed Problem actual executing

  68. Startup Speed Optimized

  69. None
  70. 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
  71. TurboFan • replace Full Codegen and Crankshaft • Optimize what

    Crankshaft cannot optimize • support ES2015+ • w/ Escape analysis
  72. None
  73. 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
  74. Lifecycle • init • before • after • destroy

  75. Node.js Native API (NAPI) “ABI stable abstraction layer of native

    module”
  76. 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
  77. 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
  78. None
  79. None
  80. None
  81. None
  82. None
  83. YourProject/* YourProject.squashfs libsquash Node.js Runtime YourProject.exe Statically Link Statically Link

  84. 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
  85. None
  86. https://github.com/pmq20/libautoupdate Libautoupdate

  87. 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
  88. None
  89. “ 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
  90. 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
  91. cf. Ko1’s Ruby AOT

  92. cf. Ko1’s Ruby AOT

  93. None
  94. http://enclose.io/ Enclose

  95. runner runner runner http://enclose.io/ Enclose

  96. None
  97. None
  98. None
  99. 谢谢