Low Efficiency of virtual functions ???? (True or false)

Source: Internet
Author: User
The reason is that there is a dynamic jump, which leads to failure of branch prediction and emptying of the pipeline.

Imagine that if it is not a virtual function, the relative address of the function is fixed during the compilation period, and the compiler can directly generate the JMP/invoke command;
If it is a virtual function, the overhead of finding a vtable is secondary. The key is that the function address is dynamic, for example
If the obtained address is in eax, all the commands that have been prefetch into the pipeline after calling eax will become invalid. The longer the pipeline, the higher the cost of a branch failure prediction.

PF-> test ();
011e146d mov eax, dword ptr [pf]
011e1470 mov edX, dword ptr [eax]
011e1472 mov ESI, ESP
011e1474 mov ECx, dword ptr [pf]
011e1477 mov eax, dword ptr [edX]
011e1479 call eax <------------------------- branch prediction failure
011e147b cmp esi, ESP
011e147d call @ ILT + 355 (_ rtc_checkesp) (11e1168h)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.