Speculative execution
Computer optimization technique
title: "Speculative execution" type: doc version: 1 created: 2026-02-28 author: "Wikipedia contributors" status: active scope: public tags: ["speculative-execution", "instruction-processing", "concurrency-(computer-science)"] description: "Computer optimization technique" topic_path: "technology/computing" source: "https://en.wikipedia.org/wiki/Speculative_execution" license: "CC BY-SA 4.0" wikipedia_page_id: 0 wikipedia_revision_id: 0
::summary Computer optimization technique ::
Speculative execution is an optimization technique where a computer system performs some task that may not be needed. Work is done before it is known whether it is actually needed, so as to prevent a delay that would have to be incurred by doing the work after it is known that it is needed. If it turns out the work was not needed after all, most changes made by the work are reverted and the results are ignored.
The objective is to provide more concurrency if extra resources are available. This approach is employed in a variety of areas, including branch prediction in pipelined processors, value prediction for exploiting value locality, prefetching memory and files, and optimistic concurrency control in database systems.{{cite conference |last1=Raghavan |first1=Prabhakar |last2=Shachnai |first2=Hadas |last3=Yaniv |first3=Mira |title=Dynamic schemes for speculative execution of code |year=1998 |doi=10.1109/MASCOT.1998.693711 |book-title=Proceedings of the Sixth International Symposium on Modeling, Analysis and Simulation of Computer and Telecommunication Systems |publisher=IEEE |pages=309–314 |author-link= H. T. Kung |first= H. T. |last= Kung |author2=John T. Robinson |title= On optimistic methods for concurrency control |book-title= ACM Trans. Database Syst. |volume= 6 |number= 2 |date=June 1981 |url=https://apps.dtic.mil/dtic/tr/fulltext/u2/a081452.pdf|archive-url=https://web.archive.org/web/20190831230313/https://apps.dtic.mil/dtic/tr/fulltext/u2/a081452.pdf|url-status=live|archive-date=August 31, 2019}}
Speculative multithreading is a special case of speculative execution.
Overview
Modern pipelined microprocessors use speculative execution to reduce the cost of conditional branch instructions using schemes that predict the execution path of a program based on the history of branch executions. In order to improve performance and utilization of computer resources, instructions can be scheduled at a time when it has not yet been determined that the instructions will need to be executed, ahead of a branch.
Variants
Speculative computation was a related earlier concept.
Eager execution
Eager execution is a form of speculative execution where both sides of the conditional branch are executed; however, the results are committed only if the predicate is true. With unlimited resources, eager execution (also known as oracle execution) would in theory provide the same performance as perfect branch prediction. With limited resources, eager execution should be employed carefully, since the number of resources needed grows exponentially with each level of branch executed eagerly.
{{Anchor|PREDICTIVE}}Predictive execution
Main article: Branch predictor
Predictive execution is a form of speculative execution where some outcome is predicted and execution proceeds along the predicted path until the actual result is known. If the prediction is true, the predicted execution is allowed to commit; however, if there is a misprediction, execution has to be unrolled and re-executed. Common forms of this include branch predictors and memory dependence prediction. A generalized form is sometimes referred to as value prediction.
Runahead
Related concepts
Lazy execution
Main article: Lazy evaluation
Lazy execution is the opposite of eager execution, and does not involve speculation. The incorporation of speculative execution into implementations of the Haskell programming language, a lazy language, is a current research topic. Eager Haskell, a variant of the language, is designed around the idea of speculative execution. A 2003 PhD thesis made GHC support a kind of speculative execution with an abortion mechanism to back out in case of a bad choice called optimistic execution. It was deemed too complicated.
Security vulnerabilities
Starting in 2017, a series of security vulnerabilities were found in the implementations of speculative execution on common processor architectures which effectively enabled an elevation of privileges.
These include:
References
References
- Lampson, Butler. (2006). "Lazy and Speculative Execution in Computer Systems". Springer.
- Bernd Krieg-Brückner. (1992). "ESOP '92: 4th European Symposium on Programming, Rennes, France, February 26-28, 1992: proceedings". Springer.
- Randy B. Osborne. (1990-03-21). "Parallel Lisp: Languages and Systems". [[Digital Equipment Corporation#Research and people.
- (1999). "Processor architecture: from dataflow to superscalar and beyond". Springer.
- (2000). "Readings in Computer Architecture". Morgan Kaufman.
- (1 August 2003). "Optimistic Evaluation: a fast evaluation strategy for non-strict programs".
- (31 August 2006). "[Haskell] Optimistic Evaluation?".
::callout[type=info title="Wikipedia Source"] This article was imported from Wikipedia and is available under the Creative Commons Attribution-ShareAlike 4.0 License. Content has been adapted to SurfDoc format. Original contributors can be found on the article history page. ::