NodeJs Addon

122c67ce0fdc3f270e8cd9017dca8068?s=47 Ravi Suhag
September 27, 2014

NodeJs Addon

Extending node with C++ using Node Addons

122c67ce0fdc3f270e8cd9017dca8068?s=128

Ravi Suhag

September 27, 2014
Tweet

Transcript

  1. node.js add-ons with C++ and V8

  2. Ravi Suhag UI/UX and Data Visualisation Consultant at Harvard University

    • Founder - Inspiration Edge, Infoclot • Developer, Designer, Hardware Hacker, Entrepreneur • Winner of 6 National and Global Hackathons in last year • Worked with Harvard University, Govt. of India, hoppr, Indiamart ! @Ravi_Suhag ravisuhag.com suhag.ravi@gmail.com About the Speaker…
  3. WTF is Node Add-ons Dynamically linked shared objects. Glue to

    C and C++ libraries !
  4. Need to know to start building ? ! • V8

    JavaScript, a C++ library for creating objects, calling functions, etc. • lbuv, C event loop library. • NODE-GYP - Build tool
  5. V8 ! • Implements ECMA-262 • Runs on OSes which

    uses IA-32, x64, or ARM processors • Enables any C++ application to expose its own objects and functions to JS code. e.g. Adobe Flash,Widgets in Apple's Mac OS X, Yahoo! Widgets
  6. libuv • Multi-platform support library with a focus on asynchronous

    I/O. • Developed for use by Node.js • Used by Mozilla's Rust language, Luvit, Julia, pyuv
  7. NODE-GYP • For compiling native addon modules for Node.js •

    Replacement to the node-waf
  8. Getting Setup • Python • Node • NPM • Node-gyp

    npm install -g node-gyp
  9. That’s enough, Let’s write some code … ! https://github.com/ravisuhag/Talks/tree/master/NodeAddons

  10. Is this hassle fruitful ? • I have a C++

    library that I’d like to use and I’m not smart enough or don’t have the time to rewrite it. • CPU heavy apps • Super-secret algorithms. - Not really !
  11. if possible write it in JS … JS ⟷ C++

    boundary is slow to cross ! function() { return Math.floor(133.7 / Math.PI); } ! • native JS ~83,333,333 calls/s • V8 return ~13,333,333 calls/s • V8 async ~1,745,200 calls/s • thread pool ~83,682 calls/s (0.1%) benchmarking by kaefer
  12. Resources • http://nodejs.org/documentation/api/ • https://developers.google.com/v8/get_started • https://github.com/TooTallNate/node-gyp/ • https://github.com/kkaefer/node-cpp-modules

  13. Thanks Slides : https://speakerdeck.com/ravisuhag/ Code Repo : https://github.com/ravisuhag/Talks/tree/master/NodeAddons ! !

    @Ravi_Suhag www.ravisuhag.com