1# Node.js code cache builder 2 3This is the V8 code cache builder of Node.js. It pre-compiles all the 4JavaScript native modules of Node.js and serializes the code cache (including 5the bytecodes) that will be embeded into the Node.js executable. When a Node.js 6JavaScript native module is `require`d at runtime, Node.js can deserialize from 7the code cache instead of parsing the source code and generating the bytecode 8for it before execution, which should reduce the load time of these JavaScript 9native modules. 10 11## How it's built and used 12 13The code cache builder is built with the `mkcodecache` target in `node.gyp` 14when `node_use_node_code_cache` is set to true, which is currently done by 15default. 16 17In the default build of the Node.js executable, to embed the V8 code cache of 18the native modules into the Node.js executable, `libnode` is first built with 19these unresolved symbols: 20 21- `node::native_module::has_code_cache` 22- `node::native_module::NativeModuleEnv::InitializeCodeCache` 23 24Then the `mkcodecache` executable is built with C++ files in this directory, 25as well as `src/node_code_cache_stub.cc` which defines the unresolved symbols. 26 27`mkcodecache` is run to generate a C++ file 28`<(SHARED_INTERMEDIATE_DIR)/node_code_cache.cc` that is similar to 29`src/node_code_cache_stub.cc` in structure, but contains the code cache data 30written as static char array literals. Then `libnode` is built with 31`node_code_cache.cc` to produce the final Node.js executable with the code 32cache data embedded. 33 34For debugging, Node.js can be built without code cache if 35`--without-node-code-cache` is passed to `configure`. Note that even if the 36code cache is not pre-compiled and embedded into the Node.js executable, the 37internal infrastructure is still used to share code cache between the main 38thread and worker threads (if there is any). 39