Closed 1261385937 closed 1 year ago
class A {
public:
virtual void f() = 0;
};
class B final: public A {
public:
void f() override;
};
class C : public A {
public:
void f() override;
};
void foo(B& b) {
b.f();
}
void bar(C& c) {
c.f();
}
and the simple asm
bar(C&):
mov rax, QWORD PTR [rdi]
jmp [QWORD PTR [rax]]
foo(B&):
jmp B::f()
Hi @1261385937, thank you for the contribution!
Do you see any difference in performance and/or assembly after applying this patch?
@Enmk
After days and nights of testing, the results have shown no significant improvement. ~~ :stuck_out_tongue_closed_eyes:
After days and nights of testing, the results have shown no significant improvement.
I believe that we might not need this optimization. Because benefits are negligible, and it also changes user-facing API, potentially breaking customer's code.
The results have shown no significant improvement. Close
Too many virtual function now :smile:. So add keyword 'final' for possible "de-virtualization" compiler optimize. Most of the time, it is effective.