Home / Companies / QuestDB / Blog / Post Details
Content Deep Dive

The Most Expensive Instruction Might Be… cmov

Blog post from QuestDB

Post Details
Company
Date Published
Author
Jaromir Hamala
Word Count
2,142
Company Posts That Month
5
Language
English
Hacker News Points
-
Post removed?
No
Summary

The exploration began with a LinkedIn comment about branch prediction and JIT compilers, leading to an investigation into how the HotSpot JVM handles branch predictions in its compiler. The author discovered that their initial comment about JIT compilers being able to emit different code for observed patterns was incorrect, as HotSpot actually measures branch bias rather than predictability, impacting performance in loops where the selected value feeds the next iteration. This bias-based measurement can result in suboptimal decisions, particularly when the branch's predictability differs from its bias. The experiments demonstrated that while the use of conditional moves (cmov) can mitigate worst-case scenarios, it consistently incurs a performance cost compared to well-predicted branches, especially in loop-dependent cases. The study highlights the complexities and trade-offs in compiler optimizations, where the heuristic used by HotSpot can overlook significant performance gains by not accounting for the actual predictability of branches.

Trends Found in this Post

No tracked trend matches for this post yet.

Use This Data

Use this post, company, and trend context to find content marketing opportunities, perform competitive analysis, or address product feature gaps via the Plushcap MCP server or the Plushcap API.