2

I m studying the Nodejs Architecture, and I wanted to understand how does the V8 engine and the Libuv library are exchanging and talking to each other ?

I m stuck by understanding, and having these options :

  • V8 compiles and the bytecode is managed by libuv ? (seems weird)
  • Something on top of V8 talks to libuv and then compiles the JS (+ libuv interaction) to bytecode
  • At compilation time, libuv is included at some layer of the code

I m quite stuck.I know the role of both part, but I don't understand how / when they are sharing information, or accessing each other APIs.

Does any body have information ?

mfrachet
  • 8,772
  • 17
  • 55
  • 110
  • Check out my answer to this other question, it should clear up your understanding: https://stackoverflow.com/questions/29883525/i-know-that-callback-function-runs-asynchronously-but-why/29885509#29885509 – slebetman Dec 04 '17 at 09:04
  • My answer to this other question provide a higher-level description of how it all work: https://stackoverflow.com/questions/19616477/does-javascript-process-using-an-elastic-racetrack-algorithm/19620041#19620041 – slebetman Dec 04 '17 at 09:05
  • I've read both of your post, thank you for these. Actually, I see this picture : JavaScript -> nodejs (+ interpreter + compiler) -> bytecode . And I don't know where the C code takes part. I think it's the source of my misunderstanding – mfrachet Dec 04 '17 at 15:29
  • It's actually this: javascript = compiler + interpreter; compiler + source code => bytecode; interpreter interprets bytecode or execute machine code or trigger JIT compiler to convert heavily used bytecode to machine code; compiler is implemented in C; interpreter is implemented in C; some of the internal libraries is machine code that was written in C (though these days a lot is actually written in js). Nodejs = program written in C that uses javascript compiler and interpreter in a loop (libuv is also processed in this same loop) – slebetman Dec 05 '17 at 02:24
  • Google Chrome = program written in C that uses javascript compiler and interpreter in a loop (libuv is also processed in this same loop); Microsoft Edge = program written in C that uses javascript compiler and interpreter in a loop (libuv is also processed in this same loop); Mozilla etc.. the same – slebetman Dec 05 '17 at 02:25
  • Actually, when I say C it's most likely C++ these days or some low level language like Rust or Swift – slebetman Dec 05 '17 at 02:26
  • You may also be interested to read the nodejs documentation of how to write modules in C++ instead of javascript (for when you need to do things that node itself does not provide): https://nodejs.org/api/addons.html – slebetman Dec 05 '17 at 02:28
  • It's now clear in my mind, I've got the same picture during the night sleep haha. Thank your for your help, promote a comment as an answer so that I can approve :D . Thank you so much :) – mfrachet Dec 05 '17 at 07:20

0 Answers0