docs/builtins/architecture.md
Builtins are the pre-compiled functions provided by V8 that implement JavaScript's standard library (e.g., Array.prototype.map, Object.create) and internal runtime helpers.
V8 implements builtins in several different ways, balancing performance, ease of writing, and platform independence.
Torque is V8's custom, strongly-typed domain-specific language. It is the modern way to write builtins. See Torque Architecture for details.
.tq files in src/builtins/..tq files into C++ CodeStubAssembler (CSA) code (compiled by TurboFan) or Turboshaft reducers (compiled by Turboshaft). V8 is currently transitioning from CSA to Turboshaft for builtins. Torque also generates C++ headers that are used by both C++ and CSA code.CSA is a low-level C++ API that allows writing code that directly generates TurboFan graphs. See CodeStubAssembler for details.
builtins-*-gen.cc and .h files in src/builtins/.Parameter, Load, Branch, CallRuntime). It bypasses the JavaScript parser and AST, and generates machine code directly via TurboFan's backend.Standard C++ functions that can be called from JavaScript or other builtins.
builtins-*.cc files in src/builtins/.Low-level builtins written using V8's MacroAssembler in C++ for specific architectures.
src/builtins/[arch]/builtins-[arch].cc.MacroAssembler to emit raw machine instructions.Builtins are compiled during V8's build process (or at startup if snapshots are not used) and are stored in the Snapshot. This ensures that V8 starts up with all standard library functions ready to execute without needing to parse or compile them.
They are shared across all Isolates and contexts in a single process.
To reduce startup time and memory sharing across Isolates, V8 embeds builtins into the binary.
Under certain conditions, V8 may copy or remap the embedded builtins into the CodeRange of a specific Isolate:
CodeRange needs to call a builtin, and the embedded blob is too far away in memory, V8 cannot use efficient PC-relative calls.v8_flags.short_builtin_calls is enabled (often depending on available physical memory), V8 will copy or remap the embedded builtins into the CodeRange so they are close to the generated code.memcpy, which increases private memory usage.docs/torque/architecture.md: Deep dive into Torque.src/builtins/: Source directory for builtins.