Use runtime information without turning it into a promise
Repeated calls reveal information about frequently taken paths and values that have appeared. A just-in-time compiler produces code while the program runs. Some implementations use this feedback to build code suited to common cases. Yet a history containing only integers is not a language-level guarantee that every future argument will also be an integer.
The central question is how to use such information while preserving behavior when a different input arrives. Begin with the syntax, semantics, and types guide, then keep source meaning, observed history, and implementation decisions separate. JIT runtimes do not all use identical tiers or terminology. The histories below are explanatory models, not logs captured from a particular release of V8 or HotSpot. Their role is to make the correctness obligations visible.
Match feedback to the actual operation semantics
Consider JavaScript function combine(a, b) { return a + b; }. Numeric arguments 2 and 3 produce 5, whereas the string "2" and the number 3 produce "23". Replacing both cases unconditionally with integer addition would be incorrect. The tiny typed language in the type-checking guide defines its own integer-only addition rule; a similar operator spelling does not transfer that rule into JavaScript.
In an illustrative history, the first thousand calls contain numbers. A runtime might use that information to favor a numeric path. If the next call contains a string, the required result still follows the language rule. Past frequency does not vote on the correct result. Describe the input classification, proposed assumption, and response to an invalid assumption together to expose what the optimization must preserve.
A guard checks whether an assumption can be used
A guard checks a condition required by an optimized path. In our model, a numeric path is entered only when its required numeric conditions hold. On failure, a runtime may choose a general path, another specialized path, or deoptimization. Every failed check does not necessarily cause the same kind of deoptimization event.
Assumptions can concern object shapes, call targets, or numeric representation ranges, rather than only a type name written in source. A path using a narrow numeric range must handle values outside that range as well. Which conditions are tested is an implementation decision. An explanatory diagram should say “assumption holds: specialized path; otherwise: a behavior-preserving path.” It should not present an invented instruction sequence as if it were a captured implementation artifact.
Reconstruct a state that can resume correctly
Deoptimization transfers execution from an optimized state into a representation that can continue more generally. Restarting the function from its beginning is not always valid. Repeating a write, transmission, or counter increment that already happened would change observable behavior. The runtime must recover where execution should resume and which values are required there.
Optimized variables may no longer occupy distinct storage, and inlined calls may not correspond one-to-one with machine frames. The runtime retains information needed to reconstruct frames and values. An object eliminated through scalar replacement may need a materialized representation when execution moves into a more general path. This connects to the allocation experiment: source construction and physical allocation can differ. Transforming representation increases the importance of information that supports a correct transition back.
Keep history, decisions, and results in separate columns
Use three conceptual stages. First, numeric calls provide feedback. Next, code relying on a condition may execute with the required checks. Finally, a different input takes a path that does not rely on the invalid assumption. In every stage, combine must return the result required by JavaScript. The illustrative call count is not a claimed optimization threshold for a particular runtime.
An implementation may later collect additional information and produce different code. There is no universal rule that one deoptimization makes a function permanently slow or immediately returns it to the identical code. Distinguish observations from inferred runtime choices. A useful table has separate columns for input, language result, assumption, and handling when that assumption cannot be used. That separation prevents a performance narrative from replacing the correctness argument.
| Illustrative stage | Input or assumption | Required result |
|---|---|---|
| Feedback | Repeated numeric 2 and 3 | 5 |
| Candidate specialization | Check required numeric conditions | 5 |
| Changed condition | String "2" and numeric 3 | "23" |
A slowdown alone does not identify deoptimization
A longer execution time after changing inputs is not sufficient evidence of deoptimization. Collection, startup work, caches, operating-system scheduling, and measurement overhead can all affect time. To claim a deoptimization event, obtain diagnostics supported by the exact runtime version and relate the relevant function and event to the measured interval.
Flags and log formats depend on the runtime release. This guide contains no measured deoptimization log and therefore supplies no fabricated deopt output. A future experiment should preserve the exact runtime version, command, input history, warmup procedure, and raw diagnostics. Diagnostic instrumentation itself may alter execution costs compared with an ordinary performance run. Establish behavior first, then use repeated measurement and independent event evidence to support an explanation of the timing result.
Separate static guarantees from runtime tendencies
Operations allowed by static type checking and representations chosen from runtime feedback belong to different layers. Knowing that a value is numeric does not necessarily prove that it fits a particular small range. Conversely, a dynamic language runtime may generate a specialized path from execution history. “Static is fast” and “dynamic cannot optimize” both omit where a relevant guarantee comes from.
Ahead-of-time compilation versus JIT is also not a binary choice between optimization and no optimization. Precompiled code may contain runtime checks, and an executing runtime may use several representations. Compare compilation time, available information, enforcement of assumptions, and handling of failure. These questions explain which transformations are justified more clearly than a runtime name alone.
Preserve failures as well as normal return values
Observable behavior includes exception ordering, not only successful return values. Reordering a failing left operand and a right operand that writes a record can introduce an effect that the original evaluation never performed. This is also why the constant-folding experiment does not simply replace 0*(1/0) with zero. A specialized path needs a correctness argument for failures and side effects alongside its ordinary result. Faster successful cases alone cannot justify a transformation.
Exercise: preserve completed side effects
Imagine incrementing a record counter before calling combine, then encountering an invalid assumption during the call. A correct transition must preserve the already completed increment while restoring the arguments and continuation state needed for the call. Simply starting the function again may repeat the effect. Annotate a conceptual diagram with completed effects and values required at resumption.
Next ask whether zero localBytes in the allocation experiment proves that combine deoptimized. It does not: the runtime, code, and metric are different. Finally change the illustrative numeric history from a thousand calls to ten thousand. Required language results stay the same. Whether a specific implementation makes a different optimization decision is a separate question requiring observation of that implementation and version.