Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimize #340

Closed
wants to merge 4 commits into from
Closed

optimize #340

wants to merge 4 commits into from

Conversation

1261385937
Copy link
Contributor

@1261385937 1261385937 commented Oct 26, 2023

Too many virtual function now 😄. So add keyword 'final' for possible "de-virtualization" compiler optimize. Most of the time, it is effective.

@1261385937
Copy link
Contributor Author

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()

@Enmk
Copy link
Collaborator

Enmk commented Oct 27, 2023

Hi @1261385937, thank you for the contribution!

Do you see any difference in performance and/or assembly after applying this patch?

@1261385937
Copy link
Contributor Author

@Enmk

After days and nights of testing, the results have shown no significant improvement.
~~ 😝

@1261385937 1261385937 marked this pull request as draft October 31, 2023 07:53
@1261385937 1261385937 marked this pull request as ready for review October 31, 2023 07:54
@1261385937 1261385937 marked this pull request as draft October 31, 2023 07:55
@Enmk
Copy link
Collaborator

Enmk commented Oct 31, 2023

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.

@1261385937
Copy link
Contributor Author

The results have shown no significant improvement. Close

@1261385937 1261385937 closed this Nov 1, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants