Back to results for “Profiling”
Node.js › Performance Optimization & Profiling

What is JIT (Just-In-Time) compilation deoptimization in V8, and how can you detect when it's hurting a hot function's performance?

Advanced

Answer

V8 initially interprets JavaScript, then compiles frequently executed ('hot') functions into optimized machine code for much faster execution -- but if that optimized function later receives an input of an unexpected shape or type it wasn't optimized for (breaking an assumption V8 made), V8 must 'deoptimize' it, discarding the fast compiled version and falling back to slower execution, potentially repeatedly if the pattern keeps recurring; this can be observed using the --trace-deopt flag, which logs every deoptimization event along with the specific reason.
node --trace-deopt server.js
# Output includes lines like:
# [deoptimizing (DEOPT eager): begin 0x... <JSFunction processItem> ... deopt reason: wrong map]
Real-world example A team notices a specific hot function's performance mysteriously degrades under certain production traffic patterns; running with --trace-deopt reveals it's being repeatedly deoptimized because it sometimes receives objects with a slightly different shape (an extra optional property) than what V8 had optimized for, fixed by ensuring the function's inputs are consistently shaped.

Common follow-ups: How does this relate back to the hidden class / object shape consistency concept discussed earlier for V8 optimization?;What's the practical performance cost of a function being repeatedly deoptimized and reoptimized under real production load?